Class: Caoutsearch::Mappings
- Inherits:
-
Object
- Object
- Caoutsearch::Mappings
- Defined in:
- lib/caoutsearch/mappings.rb
Instance Attribute Summary collapse
-
#index_name ⇒ Object
readonly
Returns the value of attribute index_name.
Instance Method Summary collapse
- #find(*args) ⇒ Object
- #find_type(*args) ⇒ Object
- #include?(*args) ⇒ Boolean
- #include_in_parent?(*args) ⇒ Boolean
-
#initialize(mappings) ⇒ Mappings
constructor
Build an index mapping.
- #nested?(*args) ⇒ Boolean
- #nested_path(*args) ⇒ Object
- #to_hash ⇒ Object (also: #as_json)
- #to_json ⇒ Object
Constructor Details
#initialize(mappings) ⇒ Mappings
Build an index mapping
Caoutsearch::Mapping.new({ properties: [...], )
11 12 13 |
# File 'lib/caoutsearch/mappings.rb', line 11 def initialize(mappings) @mappings = mappings.deep_symbolize_keys end |
Instance Attribute Details
#index_name ⇒ Object (readonly)
Returns the value of attribute index_name.
5 6 7 |
# File 'lib/caoutsearch/mappings.rb', line 5 def index_name @index_name end |
Instance Method Details
#find(*args) ⇒ Object
28 29 30 |
# File 'lib/caoutsearch/mappings.rb', line 28 def find(*args) each_path(*args).map { |hash, _| hash }.last end |
#find_type(*args) ⇒ Object
32 33 34 35 |
# File 'lib/caoutsearch/mappings.rb', line 32 def find_type(*args) definition = find(*args) definition[:type]&.to_s if definition.present? end |
#include?(*args) ⇒ Boolean
24 25 26 |
# File 'lib/caoutsearch/mappings.rb', line 24 def include?(*args) find(*args).present? end |
#include_in_parent?(*args) ⇒ Boolean
41 42 43 44 45 46 |
# File 'lib/caoutsearch/mappings.rb', line 41 def include_in_parent?(*args) path = nested_path(*args) return nil unless path !!find(path)[:include_in_parent] end |
#nested?(*args) ⇒ Boolean
37 38 39 |
# File 'lib/caoutsearch/mappings.rb', line 37 def nested?(*args) nested_path(*args).present? end |
#nested_path(*args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/caoutsearch/mappings.rb', line 48 def nested_path(*args) return nil unless include?(*args) each_path(*args) do |hash, current_path| break nil unless hash return current_path if hash[:type] == "nested" end nil end |
#to_hash ⇒ Object Also known as: as_json
15 16 17 |
# File 'lib/caoutsearch/mappings.rb', line 15 def to_hash @mappings end |
#to_json ⇒ Object
20 21 22 |
# File 'lib/caoutsearch/mappings.rb', line 20 def to_json(*) MultiJson.dump(as_json) end |