class Elastics::InstanceProxy::ModelSyncer
Attributes
class_elastics[R]
instance[R]
Public Class Methods
new(instance)
click to toggle source
# File lib/elastics/instance_proxy/model_syncer.rb, line 7 def initialize(instance) @instance = instance @class_elastics = instance.class.elastics end
Public Instance Methods
refresh_index()
click to toggle source
# File lib/elastics/instance_proxy/model_syncer.rb, line 44 def refresh_index class_elastics.refresh_index end
sync(*trail)
click to toggle source
# File lib/elastics/instance_proxy/model_syncer.rb, line 12 def sync(*trail) return if trail.include?(uid) || class_elastics.synced.nil? trail << uid class_elastics.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 #elastics proxy when synced.is_a?(Symbol) to_sync = instance.send(synced) if to_sync.respond_to?(:each) to_sync.each { |s| s.elastics.sync(*trail) } else to_sync.elastics.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.elastics.type parent_instance.elastics.sync(*trail) else raise ArgumentError, "self, string or symbol expected, got #{synced.inspect}" end end end
sync_self()
click to toggle source
# File lib/elastics/instance_proxy/model_syncer.rb, line 48 def sync_self # nothing to sync, since a ModelSyncer cannot sync itselfs end
uid()
click to toggle source
# File lib/elastics/instance_proxy/model_syncer.rb, line 40 def uid @uid ||= [instance.class, instance.id].join('-') end