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) ⇒ 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.
223 224 225 226 |
# File 'lib/replicate/active_record.rb', line 223 def initialize(object, reflection) @object = object @reflection = reflection end |
Class Method Details
.load_replicant(type, id, attrs) ⇒ Object
248 249 250 251 252 253 |
# File 'lib/replicate/active_record.rb', line 248 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
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/replicate/active_record.rb', line 231 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) ⇒ Object
242 243 244 245 246 |
# File 'lib/replicate/active_record.rb', line 242 def dump_replicant(dumper) type = self.class.name id = "#{@object.class.to_s}:#{@reflection.name}:#{@object.id}" dumper.write type, id, attributes, self end |
#id ⇒ Object
228 229 |
# File 'lib/replicate/active_record.rb', line 228 def id end |