class Elastictastic::DiscretePersistenceStrategy
Constants
- DEFAULT_HANDLER
Attributes
auto_refresh[RW]
Public Instance Methods
create(doc, &block)
click to toggle source
# File lib/elastictastic/discrete_persistence_strategy.rb, line 11 def create(doc, &block) block ||= DEFAULT_HANDLER begin response = Elastictastic.client.create( doc.index, doc.class.type, doc.id, doc.elasticsearch_doc, params_for_doc(doc) ) rescue => e return block.call(e) end doc.id = response['_id'] doc.version = response['_version'] doc.persisted! block.call end
destroy(doc, &block)
click to toggle source
# File lib/elastictastic/discrete_persistence_strategy.rb, line 48 def destroy(doc, &block) block ||= DEFAULT_HANDLER begin response = Elastictastic.client.delete( doc.index.name, doc.class.type, doc.id, params_for_doc(doc) ) rescue => e return block.call(e) end doc.transient! block.call response['found'] end
destroy!(index, type, id, routing, parent)
click to toggle source
# File lib/elastictastic/discrete_persistence_strategy.rb, line 65 def destroy!(index, type, id, routing, parent) response = Elastictastic.client.delete( index, type, id, params_for(routing, parent, nil) ) response['found'] end
update(doc, &block)
click to toggle source
# File lib/elastictastic/discrete_persistence_strategy.rb, line 30 def update(doc, &block) block ||= DEFAULT_HANDLER begin response = Elastictastic.client.update( doc.index, doc.class.type, doc.id, doc.elasticsearch_doc, params_for_doc(doc) ) rescue => e return block.call(e) end doc.version = response['_version'] doc.persisted! block.call end
Private Instance Methods
params_for(routing, parent_id, version)
click to toggle source
# File lib/elastictastic/discrete_persistence_strategy.rb, line 85 def params_for(routing, parent_id, version) {}.tap do |params| params[:refresh] = true if Elastictastic.config.auto_refresh params[:parent] = parent_id if parent_id params[:version] = version if version params[:routing] = routing.to_s if routing end end
params_for_doc(doc)
click to toggle source
# File lib/elastictastic/discrete_persistence_strategy.rb, line 77 def params_for_doc(doc) params_for( doc.class.route(doc), doc._parent_id, doc.version ) end