Class: Elastic::Core::Definition
- Inherits:
-
Object
- Object
- Elastic::Core::Definition
- Defined in:
- lib/elastic/core/definition.rb
Instance Attribute Summary collapse
-
#middleware_options ⇒ Object
readonly
Returns the value of attribute middleware_options.
Instance Method Summary collapse
- #as_es_mapping ⇒ Object
- #fields ⇒ Object
- #freeze ⇒ Object
- #get_field(_name) ⇒ Object
- #has_field?(_name) ⇒ Boolean
-
#initialize ⇒ Definition
constructor
A new instance of Definition.
- #mode ⇒ Object
- #register_field(_field) ⇒ Object
- #target ⇒ Object
- #target=(_value) ⇒ Object
Constructor Details
#initialize ⇒ Definition
Returns a new instance of Definition.
19 20 21 22 23 24 |
# File 'lib/elastic/core/definition.rb', line 19 def initialize @target = nil @field_map = {} @field_cache = {} @middleware_options = HashWithIndifferentAccess.new end |
Instance Attribute Details
#middleware_options ⇒ Object (readonly)
Returns the value of attribute middleware_options.
3 4 5 |
# File 'lib/elastic/core/definition.rb', line 3 def @middleware_options end |
Instance Method Details
#as_es_mapping ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/elastic/core/definition.rb', line 58 def as_es_mapping ensure_frozen! properties = {} @field_map.each_value do |field| properties[field.name] = field. end { 'properties' => properties.as_json } end |
#fields ⇒ Object
30 31 32 |
# File 'lib/elastic/core/definition.rb', line 30 def fields @field_map.each_value end |
#freeze ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/elastic/core/definition.rb', line 34 def freeze return if frozen? cache_target complete_and_validate_fields freeze_fields @middleware_options.freeze super end |
#get_field(_name) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/elastic/core/definition.rb', line 44 def get_field(_name) ensure_frozen! _name = _name.to_s @field_cache[_name] = resolve_field(_name) unless @field_cache.key? _name @field_cache[_name] end |
#has_field?(_name) ⇒ Boolean
52 53 54 55 56 |
# File 'lib/elastic/core/definition.rb', line 52 def has_field?(_name) ensure_frozen! !get_field(_name).nil? end |
#mode ⇒ Object
15 16 17 |
# File 'lib/elastic/core/definition.rb', line 15 def mode target.mode end |
#register_field(_field) ⇒ Object
26 27 28 |
# File 'lib/elastic/core/definition.rb', line 26 def register_field(_field) @field_map[_field.name] = _field end |
#target ⇒ Object
5 6 7 8 9 |
# File 'lib/elastic/core/definition.rb', line 5 def target raise 'attempting to access target before definition has been frozen' if @target_cache.nil? @target_cache end |
#target=(_value) ⇒ Object
11 12 13 |
# File 'lib/elastic/core/definition.rb', line 11 def target=(_value) @target = _value end |