Class: ElasticRecord::Index::Deferred::DeferredConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_record/index/deferred.rb

Defined Under Namespace

Classes: DeferredAction

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
  @index = index
  @bulk_stack = []
  reset!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elastic_record/index/deferred.rb', line 38

def method_missing(method, *args, &block)
  super unless index.real_connection.respond_to?(method)

  if READ_METHODS.include?(method)
    flush_deferred_actions!
    if method == :json_get && args.first =~ /^\/(.*)\/_search/
      index.real_connection.json_post("/#{$1.partition('/').first}/_refresh")
    end

    index.real_connection.send(method, *args, &block)
  else
    deferred_actions << DeferredAction.new(method, args, block)
  end
end

Instance Attribute Details

#bulk_stackObject

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_actionsObject

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

#indexObject

Returns the value of attribute index.



11
12
13
# File 'lib/elastic_record/index/deferred.rb', line 11

def index
  @index
end

#writes_madeObject

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

#reset!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/elastic_record/index/deferred.rb', line 22

def reset!
  if writes_made
    begin
      index.disable_deferring!
      index.refresh
      index.delete_by_query query: {match_all: {}}
    ensure
      index.enable_deferring!
    end
  end
  self.deferred_actions = []
  self.writes_made = false
end