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.



5
6
7
# File 'lib/factory_trace/tracker.rb', line 5

def initialize
  @storage = {}
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



3
4
5
# File 'lib/factory_trace/tracker.rb', line 3

def storage
  @storage
end

Instance Method Details

#track!Object



9
10
11
12
13
14
15
16
17
# File 'lib/factory_trace/tracker.rb', line 9

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