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
-
#collector ⇒ Object
Returns the value of attribute collector.
-
#connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
- #compile(node, collector = Arel::Collectors::ElasticsearchQuery.new) ⇒ Object
- #dispatch_as(mode) ⇒ Object
- #initialize(connection) ⇒ Object
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
63 64 65 66 67 |
# File 'lib/arel/visitors/elasticsearch_base.rb', line 63 def method_missing(method, *args, &block) raise(UnsupportedVisitError, method.to_s) if method.to_s[0..4] == 'visit' super end |
Instance Attribute Details
#collector ⇒ Object
Returns the value of attribute collector.
16 17 18 |
# File 'lib/arel/visitors/elasticsearch_base.rb', line 16 def collector @collector end |
#connection ⇒ Object
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_cache ⇒ Object
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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/arel/visitors/elasticsearch_base.rb', line 42 def compile(node, collector = Arel::Collectors::ElasticsearchQuery.new) # IMPORTANT: To prevent persistent assigned variables due *accept* exceptions, those must be 'reset' before each compile. # # required for nested assignment. # see +#assign+ method @nested = false @nested_args = [] # 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
32 33 34 35 36 37 38 39 40 |
# File 'lib/arel/visitors/elasticsearch_base.rb', line 32 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 |
# File 'lib/arel/visitors/elasticsearch_base.rb', line 27 def initialize(connection) super() @connection = connection end |