Class: Replicate::AR::Habtm
- Inherits:
-
Object
- Object
- Replicate::AR::Habtm
- Defined in:
- lib/replicate/active_record.rb
Overview
Special object used to dump the list of associated ids for a has_and_belongs_to_many association. The object includes attributes for locating the source object and writing the list of ids to the appropriate association method.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #dump_replicant(dumper, opts = {}) ⇒ Object
- #id ⇒ Object
-
#initialize(object, reflection) ⇒ Habtm
constructor
A new instance of Habtm.
Constructor Details
#initialize(object, reflection) ⇒ Habtm
Returns a new instance of Habtm.
325 326 327 328 |
# File 'lib/replicate/active_record.rb', line 325 def initialize(object, reflection) @object = object @reflection = reflection end |
Class Method Details
.load_replicant(type, id, attrs) ⇒ Object
350 351 352 353 354 355 |
# File 'lib/replicate/active_record.rb', line 350 def self.load_replicant(type, id, attrs) object = attrs['class'].constantize.find(attrs['id']) ids = attrs['collection'] object.__send__("#{attrs['ref_name'].to_s.singularize}_ids=", ids) [id, new(object, nil)] end |
Instance Method Details
#attributes ⇒ Object
333 334 335 336 337 338 339 340 341 342 |
# File 'lib/replicate/active_record.rb', line 333 def attributes ids = @object.__send__("#{@reflection.name.to_s.singularize}_ids") { 'id' => [:id, @object.class.to_s, @object.id], 'class' => @object.class.to_s, 'ref_class' => @reflection.klass.to_s, 'ref_name' => @reflection.name.to_s, 'collection' => [:id, @reflection.klass.to_s, ids] } end |
#dump_replicant(dumper, opts = {}) ⇒ Object
344 345 346 347 348 |
# File 'lib/replicate/active_record.rb', line 344 def dump_replicant(dumper, opts={}) type = self.class.name id = "#{@object.class.to_s}:#{@reflection.name}:#{@object.id}" dumper.write type, id, attributes, self end |
#id ⇒ Object
330 331 |
# File 'lib/replicate/active_record.rb', line 330 def id end |