Class: Elastictastic::ScopeBuilder

Inherits:
BasicObject
Defined in:
lib/elastictastic/scope_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ ScopeBuilder

Returns a new instance of ScopeBuilder.



11
12
13
# File 'lib/elastictastic/scope_builder.rb', line 11

def initialize(&block)
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



21
22
23
24
25
26
27
28
29
30
# File 'lib/elastictastic/scope_builder.rb', line 21

def method_missing(method, *args, &block)
  args << ScopeBuilder.build(&block) if block
  value =
    case args.length
    when 0 then {}
    when 1 then args.first
    else args
    end
  @scope[method.to_s] = value
end

Class Method Details

.build(&block) ⇒ Object



6
7
8
# File 'lib/elastictastic/scope_builder.rb', line 6

def build(&block)
  new(&block).build
end

Instance Method Details

#buildObject



15
16
17
18
19
# File 'lib/elastictastic/scope_builder.rb', line 15

def build
  @scope = {}
  instance_eval(&@block)
  @scope
end