Module: ModelSync::Base::Config

Defined in:
lib/model_sync.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mapping_blockObject (readonly)

Returns the value of attribute mapping_block.



10
11
12
# File 'lib/model_sync.rb', line 10

def mapping_block
  @mapping_block
end

#mappingsObject (readonly)

Returns the value of attribute mappings.



10
11
12
# File 'lib/model_sync.rb', line 10

def mappings
  @mappings
end

#relationshipObject (readonly)

Returns the value of attribute relationship.



10
11
12
# File 'lib/model_sync.rb', line 10

def relationship
  @relationship
end

#slave_model_classObject (readonly)

Returns the value of attribute slave_model_class.



10
11
12
# File 'lib/model_sync.rb', line 10

def slave_model_class
  @slave_model_class
end

#slave_model_nameObject (readonly)

Returns the value of attribute slave_model_name.



10
11
12
# File 'lib/model_sync.rb', line 10

def slave_model_name
  @slave_model_name
end

Instance Method Details

#model_sync(options) ⇒ Object



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

def model_sync(options)
  @slave_model_name = options[:sync_to].to_s.downcase
  @slave_model_class = Kernel.const_get(@slave_model_name.classify)
  @relationship = options[:relationship]
  @mappings = options[:mappings]
  @mapping_block = options[:mapping_block]

  # Add a callback to sync_changes on every save
  self.after_save :sync_changes
  self.after_destroy :destroy_slave
end