Class: Chewy::Fields::Base
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #compose(*objects) ⇒ Object
-
#initialize(name, value: nil, **options) ⇒ Base
constructor
A new instance of Base.
- #mappings_hash ⇒ Object
- #multi_field? ⇒ Boolean
- #object_field? ⇒ Boolean
- #update_options!(**options) ⇒ Object
Constructor Details
#initialize(name, value: nil, **options) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 |
# File 'lib/chewy/fields/base.rb', line 7 def initialize(name, value: nil, **) @name = name.to_sym @options = {} (**) @value = value @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/chewy/fields/base.rb', line 4 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/chewy/fields/base.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/chewy/fields/base.rb', line 4 def @options end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/chewy/fields/base.rb', line 5 def parent @parent end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/chewy/fields/base.rb', line 4 def value @value end |
Instance Method Details
#compose(*objects) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chewy/fields/base.rb', line 46 def compose(*objects) result = evaluate(objects) if children.present? && !multi_field? result = if result.respond_to?(:to_ary) result.to_ary.map { |item| compose_children(item, *objects) } else compose_children(result, *objects) end end {name => result} end |
#mappings_hash ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chewy/fields/base.rb', line 27 def mappings_hash mapping = if children.present? {(multi_field? ? :fields : :properties) => children.map(&:mappings_hash).inject(:merge)} else {} end mapping.reverse_merge!() mapping.reverse_merge!(type: (children.present? ? 'object' : Chewy.default_field_type)) # This is done to support ES2 journaling and will be removed soon if mapping[:type] == 'keyword' && Chewy::Runtime.version < '5.0' mapping[:type] = 'string' mapping[:index] = 'not_analyzed' end {name => mapping} end |
#multi_field? ⇒ Boolean
19 20 21 |
# File 'lib/chewy/fields/base.rb', line 19 def multi_field? children.present? && !object_field? end |
#object_field? ⇒ Boolean
23 24 25 |
# File 'lib/chewy/fields/base.rb', line 23 def object_field? (children.present? && [:type].blank?) || %w[object nested].include?([:type].to_s) end |
#update_options!(**options) ⇒ Object
15 16 17 |
# File 'lib/chewy/fields/base.rb', line 15 def (**) @options = end |