Module: ModelSync::Base
Defined Under Namespace
Modules: Config
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/model_sync.rb', line 34
def method_missing(id, *args, &block)
case(id.to_s)
when /^create_#{self.class.slave_model_name}$/
unless find_slave_instance
new_instance = self.class.slave_model_class.new
perform_sync(new_instance)
new_instance.id = self.id
new_instance.save
end
when /^synch?ed_with_#{self.class.slave_model_name}\?$/
!!find_slave_instance
else
super
end
end
|
Class Method Details
.included(klass) ⇒ Object
3
4
5
6
7
|
# File 'lib/model_sync.rb', line 3
def self.included(klass)
klass.class_eval do
extend Config
end
end
|
Instance Method Details
#sync_changes ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/model_sync.rb', line 25
def sync_changes
if slave_instance = find_slave_instance
perform_sync(slave_instance)
slave_instance.save
end
end
|