Class: ElasticGraph::SchemaArtifacts::RuntimeMetadata::SortField
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaArtifacts::RuntimeMetadata::SortField
- Defined in:
- lib/elastic_graph/schema_artifacts/runtime_metadata/sort_field.rb
Constant Summary collapse
- FIELD_PATH =
"field_path"- DIRECTION =
"direction"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(field_path:, direction:) ⇒ SortField
constructor
A new instance of SortField.
- #to_dumpable_hash ⇒ Object
- #to_query_clause ⇒ Object
Constructor Details
#initialize(field_path:, direction:) ⇒ SortField
Returns a new instance of SortField.
15 16 17 18 19 20 21 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/sort_field.rb', line 15 def initialize(field_path:, direction:) unless direction == :asc || direction == :desc raise SchemaError, "Sort direction `#{direction.inspect}` is invalid; it must be `:asc` or `:desc`" end super(field_path: field_path, direction: direction) end |
Class Method Details
.from_hash(hash) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/sort_field.rb', line 26 def self.from_hash(hash) new( field_path: hash[FIELD_PATH], direction: hash.fetch(DIRECTION).to_sym ) end |
Instance Method Details
#to_dumpable_hash ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/sort_field.rb', line 33 def to_dumpable_hash { # Keys here are ordered alphabetically; please keep them that way. DIRECTION => direction.to_s, FIELD_PATH => field_path } end |
#to_query_clause ⇒ Object
41 42 43 |
# File 'lib/elastic_graph/schema_artifacts/runtime_metadata/sort_field.rb', line 41 def to_query_clause {field_path => {"order" => direction.to_s}} end |