Class: Elastictastic::Field
- Inherits:
- BasicObject
- Defined in:
- lib/elastictastic/field.rb
Class Method Summary collapse
Instance Method Summary collapse
- #field(field_name, options = {}) ⇒ Object
-
#initialize(field_name, default_options, properties, &block) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(field_name, default_options, properties, &block) ⇒ Field
Returns a new instance of Field.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/elastictastic/field.rb', line 23 def initialize(field_name, , properties, &block) @field_name = field_name @properties = properties if block @properties['type'] = 'multi_field' @properties['fields'] = { field_name.to_s => Field.with_defaults() } instance_eval(&block) else @properties.merge!(Field.with_defaults()) end end |
Class Method Details
.process(field_name, default_options, &block) ⇒ Object
5 6 7 8 9 |
# File 'lib/elastictastic/field.rb', line 5 def self.process(field_name, , &block) {}.tap do |properties| new(field_name, , properties, &block) end end |
.with_defaults(options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/elastictastic/field.rb', line 11 def self.with_defaults() = Util.deep_stringify() if preset = .delete('preset') = ::Elastictastic.config.presets[preset].merge() end { 'type' => 'string' }.merge().tap do |field_properties| if field_properties['type'].to_s == 'date' field_properties['format'] = 'date_time_no_millis' end end end |
Instance Method Details
#field(field_name, options = {}) ⇒ Object
36 37 38 39 |
# File 'lib/elastictastic/field.rb', line 36 def field(field_name, = {}) @properties['fields'][field_name.to_s] = Field.with_defaults() end |