Class: Flex::InstanceProxy::ModelSyncer
- Inherits:
-
Object
- Object
- Flex::InstanceProxy::ModelSyncer
- Defined in:
- lib/flex/instance_proxy/model_syncer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#class_flex ⇒ Object
readonly
Returns the value of attribute class_flex.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
-
#initialize(instance) ⇒ ModelSyncer
constructor
A new instance of ModelSyncer.
- #refresh_index ⇒ Object
- #sync(*trail) ⇒ Object
- #sync_self ⇒ Object
- #uid ⇒ Object
Constructor Details
#initialize(instance) ⇒ ModelSyncer
Returns a new instance of ModelSyncer.
7 8 9 10 |
# File 'lib/flex/instance_proxy/model_syncer.rb', line 7 def initialize(instance) @instance = instance @class_flex = instance.class.flex end |
Instance Attribute Details
#class_flex ⇒ Object (readonly)
Returns the value of attribute class_flex.
5 6 7 |
# File 'lib/flex/instance_proxy/model_syncer.rb', line 5 def class_flex @class_flex end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
5 6 7 |
# File 'lib/flex/instance_proxy/model_syncer.rb', line 5 def instance @instance end |
Instance Method Details
#refresh_index ⇒ Object
44 45 46 |
# File 'lib/flex/instance_proxy/model_syncer.rb', line 44 def refresh_index class_flex.refresh_index end |
#sync(*trail) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/flex/instance_proxy/model_syncer.rb', line 12 def sync(*trail) return if trail.include?(uid) || class_flex.synced.nil? trail << uid class_flex.synced.each do |synced| case # sync self when synced == instance.class sync_self # sync :author, :comments # works for all association types, if the instances have a #flex proxy when synced.is_a?(Symbol) to_sync = instance.send(synced) if to_sync.respond_to?(:each) to_sync.each { |s| s.flex.sync(*trail) } else to_sync.flex.sync(*trail) end # sync 'blog' # polymorphic: use this form only if you want to sync any specific parent type but not all when synced.is_a?(String) next unless synced == parent_instance.flex.type parent_instance.flex.sync(*trail) else raise ArgumentError, "self, string or symbol expected, got #{synced.inspect}" end end end |
#sync_self ⇒ Object
48 49 50 |
# File 'lib/flex/instance_proxy/model_syncer.rb', line 48 def sync_self # nothing to sync, since a ModelSyncer cannot sync itselfs end |
#uid ⇒ Object
40 41 42 |
# File 'lib/flex/instance_proxy/model_syncer.rb', line 40 def uid @uid ||= [instance.class, instance.id].join('-') end |