Class: Elastictastic::DiscretePersistenceStrategy
- Inherits:
-
Object
- Object
- Elastictastic::DiscretePersistenceStrategy
- Includes:
- Singleton
- Defined in:
- lib/elastictastic/discrete_persistence_strategy.rb
Constant Summary collapse
- DEFAULT_HANDLER =
proc { |e| raise(e) if e }
Instance Attribute Summary collapse
-
#auto_refresh ⇒ Object
Returns the value of attribute auto_refresh.
Instance Method Summary collapse
- #create(doc, &block) ⇒ Object
- #destroy(doc, &block) ⇒ Object
- #destroy!(index, type, id, routing, parent) ⇒ Object
- #update(doc, &block) ⇒ Object
Instance Attribute Details
#auto_refresh ⇒ Object
Returns the value of attribute auto_refresh.
9 10 11 |
# File 'lib/elastictastic/discrete_persistence_strategy.rb', line 9 def auto_refresh @auto_refresh end |
Instance Method Details
#create(doc, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# 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) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |