Module: Arel::Visitors::ElasticsearchBase

Extended by:
ActiveSupport::Concern
Included in:
Elasticsearch
Defined in:
lib/arel/visitors/elasticsearch_base.rb

Defined Under Namespace

Classes: UnsupportedVisitError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

auto prevent visits on missing nodes



61
62
63
64
65
# File 'lib/arel/visitors/elasticsearch_base.rb', line 61

def method_missing(method, *args, &block)
  raise(UnsupportedVisitError, method.to_s) if method.to_s[0..4] == 'visit'

  super
end

Instance Attribute Details

#collectorObject

Returns the value of attribute collector.



16
17
18
# File 'lib/arel/visitors/elasticsearch_base.rb', line 16

def collector
  @collector
end

#connectionObject

Returns the value of attribute connection.



15
16
17
# File 'lib/arel/visitors/elasticsearch_base.rb', line 15

def connection
  @connection
end

Class Method Details

.simple_dispatch_cacheObject



20
21
22
23
24
# File 'lib/arel/visitors/elasticsearch_base.rb', line 20

def simple_dispatch_cache
  @simple_dispatch_cache ||= Hash.new do |hash, klass|
    hash[klass] = "visit_#{(klass.name.demodulize || 'unknown')}"
  end
end

Instance Method Details

#compile(node, collector = Arel::Collectors::ElasticsearchQuery.new) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/arel/visitors/elasticsearch_base.rb', line 47

def compile(node, collector = Arel::Collectors::ElasticsearchQuery.new)
  # we don't need to forward the collector each time - we just set it and always access it, when we need.
  self.collector = collector

  # so we just visit the first node without any additionally provided collector ...
  accept(node)

  # ... and return the final result
  self.collector.value
end

#dispatch_as(mode) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/arel/visitors/elasticsearch_base.rb', line 37

def dispatch_as(mode)
  current, @dispatch = @dispatch, (mode == :simple ? self.class.simple_dispatch_cache : self.class.dispatch_cache)

  res = yield

  @dispatch = current

  res
end

#initialize(connection) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/arel/visitors/elasticsearch_base.rb', line 27

def initialize(connection)
  super()
  @connection = connection

  # required for nested assignment.
  # see +#assign+ method
  @nested      = false
  @nested_args = []
end