Class: Elasticated::Mapping::FieldsBuilder
Instance Attribute Summary collapse
Instance Method Summary
collapse
#evaluate
Constructor Details
Returns a new instance of FieldsBuilder.
9
10
11
12
13
14
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 9
def initialize(name)
self.fields = Array.new
self.sub_objects = Array.new
self.nesteds = Array.new
self.name = name
end
|
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
7
8
9
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 7
def fields
@fields
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 7
def name
@name
end
|
#nesteds ⇒ Object
Returns the value of attribute nesteds.
7
8
9
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 7
def nesteds
@nesteds
end
|
#sub_objects ⇒ Object
Returns the value of attribute sub_objects.
7
8
9
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 7
def sub_objects
@sub_objects
end
|
Instance Method Details
#add_property(field) ⇒ Object
16
17
18
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 16
def add_property(field)
fields << field
end
|
#analyzed_string(field_name) ⇒ Object
44
45
46
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 44
def analyzed_string(field_name)
add_property Fields::AnalyzedStringField.new(field_name)
end
|
#boolean(field_name) ⇒ Object
Also known as:
bool
48
49
50
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 48
def boolean(field_name)
add_property Fields::BooleanField.new(field_name)
end
|
#build ⇒ Object
83
84
85
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 83
def build
{ name => build_body }
end
|
#build_body ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 69
def build_body
ret = Hash.new
fields.each do |field|
ret.merge! field.build
end
sub_objects.each do |sub_object|
ret.merge! sub_object.build
end
nesteds.each do |nested|
ret.merge! nested.build
end
ret
end
|
#date(field_name) ⇒ Object
20
21
22
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 20
def date(field_name)
add_property Fields::DateField.new(field_name)
end
|
#double(field_name) ⇒ Object
32
33
34
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 32
def double(field_name)
add_property Fields::DoubleField.new(field_name)
end
|
#float(field_name) ⇒ Object
28
29
30
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 28
def float(field_name)
add_property Fields::FloatField.new(field_name)
end
|
#integer(field_name) ⇒ Object
36
37
38
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 36
def integer(field_name)
add_property Fields::IntegerField.new(field_name)
end
|
#long(field_name) ⇒ Object
40
41
42
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 40
def long(field_name)
add_property Fields::LongField.new(field_name)
end
|
#nested(nested_name, &block) ⇒ Object
59
60
61
62
63
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 59
def nested(nested_name, &block)
nested = NestedBuilder.new nested_name
nested.evaluate block
nesteds << nested
end
|
#object(object_name, &block) ⇒ Object
53
54
55
56
57
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 53
def object(object_name, &block)
sub_object = ObjectBuilder.new object_name
sub_object.evaluate block
sub_objects << sub_object
end
|
#partial(partial_mapping) ⇒ Object
65
66
67
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 65
def partial(partial_mapping)
partial_mapping.apply_over self
end
|
#string(field_name) ⇒ Object
24
25
26
|
# File 'lib/elasticated/mapping/fields_builder.rb', line 24
def string(field_name)
add_property Fields::StringField.new(field_name)
end
|