Class: Paquito::ActiveRecordCoder::InstanceTracker
- Inherits:
-
Object
- Object
- Paquito::ActiveRecordCoder::InstanceTracker
- Defined in:
- lib/paquito/active_record_coder.rb
Instance Method Summary collapse
- #fetch(*args, &block) ⇒ Object
-
#initialize ⇒ InstanceTracker
constructor
A new instance of InstanceTracker.
- #lookup(instance) ⇒ Object
- #map(&block) ⇒ Object
- #push(instance) ⇒ Object
Constructor Details
#initialize ⇒ InstanceTracker
Returns a new instance of InstanceTracker.
126 127 128 129 |
# File 'lib/paquito/active_record_coder.rb', line 126 def initialize @instances = [] @ids = {}.compare_by_identity end |
Instance Method Details
#fetch(*args, &block) ⇒ Object
135 136 137 |
# File 'lib/paquito/active_record_coder.rb', line 135 def fetch(*args, &block) @instances.fetch(*args, &block) end |
#lookup(instance) ⇒ Object
146 147 148 |
# File 'lib/paquito/active_record_coder.rb', line 146 def lookup(instance) @ids[instance] end |
#map(&block) ⇒ Object
131 132 133 |
# File 'lib/paquito/active_record_coder.rb', line 131 def map(&block) @instances.map(&block) end |
#push(instance) ⇒ Object
140 141 142 143 144 |
# File 'lib/paquito/active_record_coder.rb', line 140 def push(instance) id = @ids[instance] = @instances.size @instances << instance id end |