Class: ElasticRecord::Index::Deferred::DeferredConnection
- Inherits:
-
Object
- Object
- ElasticRecord::Index::Deferred::DeferredConnection
- Defined in:
- lib/elastic_record/index/deferred.rb
Defined Under Namespace
Classes: DeferredAction
Instance Attribute Summary collapse
-
#bulk_stack ⇒ Object
Returns the value of attribute bulk_stack.
-
#deferred_actions ⇒ Object
Returns the value of attribute deferred_actions.
-
#index ⇒ Object
Returns the value of attribute index.
-
#writes_made ⇒ Object
Returns the value of attribute writes_made.
Instance Method Summary collapse
- #flush! ⇒ Object
-
#initialize(index) ⇒ DeferredConnection
constructor
A new instance of DeferredConnection.
- #reset! ⇒ Object
Constructor Details
#initialize(index) ⇒ DeferredConnection
Returns a new instance of DeferredConnection.
16 17 18 19 20 |
# File 'lib/elastic_record/index/deferred.rb', line 16 def initialize(index) self.index = index self.bulk_stack = [] reset! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/elastic_record/index/deferred.rb', line 45 def method_missing(method, *args, &block) super unless index.real_connection.respond_to?(method) if READ_METHODS.include?(method) flush! index.real_connection.json_post("/#{index.alias_name}/_refresh") if requires_refresh?(method, *args) index.real_connection.send(method, *args, &block) else deferred_actions << DeferredAction.new(method, args, block) end end |
Instance Attribute Details
#bulk_stack ⇒ Object
Returns the value of attribute bulk_stack.
14 15 16 |
# File 'lib/elastic_record/index/deferred.rb', line 14 def bulk_stack @bulk_stack end |
#deferred_actions ⇒ Object
Returns the value of attribute deferred_actions.
12 13 14 |
# File 'lib/elastic_record/index/deferred.rb', line 12 def deferred_actions @deferred_actions end |
#index ⇒ Object
Returns the value of attribute index.
11 12 13 |
# File 'lib/elastic_record/index/deferred.rb', line 11 def index @index end |
#writes_made ⇒ Object
Returns the value of attribute writes_made.
13 14 15 |
# File 'lib/elastic_record/index/deferred.rb', line 13 def writes_made @writes_made end |
Instance Method Details
#flush! ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/elastic_record/index/deferred.rb', line 35 def flush! deferred_actions.each do |queued_action| self.writes_made = true queued_action.run(index.real_connection) end deferred_actions.clear end |
#reset! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/elastic_record/index/deferred.rb', line 22 def reset! if writes_made begin index.disable_deferring! index.delete_by_query match_all: {} ensure index.enable_deferring! end end self.deferred_actions = [] self.writes_made = false end |