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.
146 147 148 149 |
# File 'lib/paquito/active_record_coder.rb', line 146 def initialize @instances = [] @ids = {}.compare_by_identity end |
Instance Method Details
#fetch(*args, &block) ⇒ Object
155 156 157 |
# File 'lib/paquito/active_record_coder.rb', line 155 def fetch(*args, &block) @instances.fetch(*args, &block) end |
#lookup(instance) ⇒ Object
166 167 168 |
# File 'lib/paquito/active_record_coder.rb', line 166 def lookup(instance) @ids[instance] end |
#map(&block) ⇒ Object
151 152 153 |
# File 'lib/paquito/active_record_coder.rb', line 151 def map(&block) @instances.map(&block) end |
#push(instance) ⇒ Object
160 161 162 163 164 |
# File 'lib/paquito/active_record_coder.rb', line 160 def push(instance) id = @ids[instance] = @instances.size @instances << instance id end |