Class: FactoryTrace::FixtureTracker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFixtureTracker

Returns a new instance of FixtureTracker.



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

def initialize
  @storage = {}
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



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

def storage
  @storage
end

Instance Method Details

#track!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/factory_trace/fixture_tracker.rb', line 11

def track!
  tracker_storage = @storage

  ::ActiveRecord::FixtureSet.prepend(Module.new do
    define_method(:[]) do |fixture_name|
      if fixture_name
        tracker_storage[name] ||= Set.new
        tracker_storage[name].add(fixture_name.to_s)
      end
      super(fixture_name)
    end
  end)
end