Class: Foundries::Recording::Collector
- Inherits:
-
Object
- Object
- Foundries::Recording::Collector
- Defined in:
- lib/foundries/recording/collector.rb
Defined Under Namespace
Classes: MutableNode, Subscriber
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#total_creates ⇒ Object
readonly
Returns the value of attribute total_creates.
Instance Method Summary collapse
- #handle_finish(payload) ⇒ Object
- #handle_start(payload) ⇒ Object
-
#initialize ⇒ Collector
constructor
A new instance of Collector.
- #start_test(test_id) ⇒ Object
- #stop_test(test_id) ⇒ Object
Constructor Details
#initialize ⇒ Collector
Returns a new instance of Collector.
9 10 11 12 13 14 15 |
# File 'lib/foundries/recording/collector.rb', line 9 def initialize @results = {} @total_creates = 0 @subscriber = nil @stack = nil @current_root = nil end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
36 37 38 |
# File 'lib/foundries/recording/collector.rb', line 36 def results @results end |
#total_creates ⇒ Object (readonly)
Returns the value of attribute total_creates.
38 39 40 |
# File 'lib/foundries/recording/collector.rb', line 38 def total_creates @total_creates end |
Instance Method Details
#handle_finish(payload) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/foundries/recording/collector.rb', line 51 def handle_finish(payload) return unless payload[:strategy] == :create @stack.pop @total_creates += 1 end |
#handle_start(payload) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/foundries/recording/collector.rb', line 41 def handle_start(payload) return unless payload[:strategy] == :create traits = payload[:traits] || [] mutable = MutableNode.new(payload[:name], traits) @stack.last.children << mutable @stack.push(mutable) end |
#start_test(test_id) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/foundries/recording/collector.rb', line 17 def start_test(test_id) @current_root = MutableNode.new(:__root__, []) @stack = [@current_root] @subscriber = ActiveSupport::Notifications.subscribe( "factory_bot.run_factory", Subscriber.new(self) ) end |
#stop_test(test_id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/foundries/recording/collector.rb', line 27 def stop_test(test_id) ActiveSupport::Notifications.unsubscribe(@subscriber) @subscriber = nil @results[test_id] = freeze_tree(@current_root) @stack = nil @current_root = nil end |