Class: FactoryTrace::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_trace/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTracker

Returns a new instance of Tracker.



9
10
11
# File 'lib/factory_trace/tracker.rb', line 9

def initialize
  @storage = {}
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



7
8
9
# File 'lib/factory_trace/tracker.rb', line 7

def storage
  @storage
end

Instance Method Details

#track!Object



13
14
15
16
17
18
19
20
21
# File 'lib/factory_trace/tracker.rb', line 13

def track!
  ActiveSupport::Notifications.subscribe("factory_bot.run_factory") do |_name, _start, _finish, _id, payload|
    name = payload[:name].to_s
    traits = payload[:traits].map(&:to_s)

    storage[name] ||= Set.new
    storage[name] |= traits
  end
end