class Elastic::Fields::Value
Attributes
name[R]
Public Class Methods
new(_name, _options)
click to toggle source
# File lib/elastic/fields/value.rb, line 14 def initialize(_name, _options) @name = _name.to_s @options = _options.symbolize_keys @mapping_inference = true end
Public Instance Methods
disable_mapping_inference()
click to toggle source
# File lib/elastic/fields/value.rb, line 42 def disable_mapping_inference @mapping_inference = false end
freeze()
click to toggle source
# File lib/elastic/fields/value.rb, line 46 def freeze @name.freeze @options.freeze load_transform_and_datatype end
get_field(_name)
click to toggle source
# File lib/elastic/fields/value.rb, line 29 def get_field(_name) nil end
merge!(_options)
click to toggle source
# File lib/elastic/fields/value.rb, line 24 def merge!(_options) return if _options.nil? @options.merge! _options.symbolize_keys end
needs_inference?()
click to toggle source
# File lib/elastic/fields/value.rb, line 38 def needs_inference? mapping_inference_enabled? && !@options.key?(:type) end
nested?()
click to toggle source
# File lib/elastic/fields/value.rb, line 20 def nested? false end
prepare_value_for_index(_value)
click to toggle source
# File lib/elastic/fields/value.rb, line 57 def prepare_value_for_index(_value) _value = @transform.apply _value if @transform @datatype.prepare_for_index _value end
prepare_value_for_query(_value)
click to toggle source
# File lib/elastic/fields/value.rb, line 52 def prepare_value_for_query(_value) _value = @transform.apply _value if @transform @datatype.prepare_for_query _value end
validate()
click to toggle source
# File lib/elastic/fields/value.rb, line 33 def validate return "explicit field type for #{@name} required" unless @options.key? :type nil end
Private Instance Methods
datatype_class()
click to toggle source
# File lib/elastic/fields/value.rb, line 73 def datatype_class case @options[:type] when Symbol, String load_registered_datatype @options[:type].to_sym when nil Elastic::Datatypes::Default else @options[:type] end end
load_registered_datatype(_name)
click to toggle source
# File lib/elastic/fields/value.rb, line 84 def load_registered_datatype(_name) # TODO: replace this with a datatype registry case _name when :term, :keyword Elastic::Datatypes::Term when :string, :text Elastic::Datatypes::String when :date Elastic::Datatypes::Date when :time Elastic::Datatypes::Time else Elastic::Datatypes::Default end end
load_transform_and_datatype()
click to toggle source
# File lib/elastic/fields/value.rb, line 64 def load_transform_and_datatype @datatype = datatype_class.new(@name, @options) @transform = Elastic::Support::Transform.new @options[:transform] if @options.key? :transform end
mapping_inference_enabled?()
click to toggle source
# File lib/elastic/fields/value.rb, line 69 def mapping_inference_enabled? @mapping_inference && !@options.key?(:transform) end