Class: Elasticated::Mapping::Builder

Inherits:
Object
  • Object
show all
Includes:
Elasticated::Mixins::BlockEvaluation
Defined in:
lib/elasticated/mapping/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Elasticated::Mixins::BlockEvaluation

#evaluate

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



18
19
20
# File 'lib/elasticated/mapping/builder.rb', line 18

def initialize
  self.mapping_types = Array.new
end

Instance Attribute Details

#mapping_typesObject

Returns the value of attribute mapping_types.



15
16
17
# File 'lib/elasticated/mapping/builder.rb', line 15

def mapping_types
  @mapping_types
end

Class Method Details

.build(&block) ⇒ Object



6
7
8
9
10
# File 'lib/elasticated/mapping/builder.rb', line 6

def build(&block)
  instance = new
  instance.evaluate block
  instance
end

Instance Method Details

#buildObject Also known as: to_h



28
29
30
31
32
# File 'lib/elasticated/mapping/builder.rb', line 28

def build
  mapping_types.inject({}) do |hash, mapping_type|
    hash.merge mapping_type.build
  end
end

#type(name, &block) ⇒ Object



22
23
24
25
26
# File 'lib/elasticated/mapping/builder.rb', line 22

def type(name, &block)
  mapping_type = TypeBuilder.new name
  mapping_type.evaluate block
  mapping_types << mapping_type
end