Class: Elastics::InstanceProxy::ActiveModel

Inherits:
ModelIndexer show all
Defined in:
lib/elastics/instance_proxy/active_model.rb

Instance Method Summary collapse

Methods included from ModelIndexer

#elastics, #elastics_action, #elastics_indexable?, #elastics_source, included

Instance Method Details

#store(*vars) ⇒ Object



5
6
7
8
9
# File 'lib/elastics/instance_proxy/active_model.rb', line 5

def store(*vars)
  return super unless instance.elastics_indexable? # this should never happen since elastics_indexable? returns true
  meth = (id.nil? || id.empty?) ? :post_store : :put_store
  Elastics.send(meth, metainfo, {:data => instance.elastics_source}, *vars)
end

#sync_selfObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/elastics/instance_proxy/active_model.rb', line 11

def sync_self
  instance.instance_eval do
    if destroyed?
      if @skip_destroy_callbacks
        elastics.remove
      else
        run_callbacks :destroy do
          elastics.remove
        end
      end
    else
      run_callbacks :save do
        context = new_record? ? :create : :update
        run_callbacks(context) do
          result    = context == :create ? elastics.store : elastics.store(:params => { :version => _version })
          @_id      = result['_id']
          @_version = result['_version']
        end
      end
    end
  end
end