Class: ElasticGraph::SchemaDefinition::SchemaElements::EnumsForIndexedTypes
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaDefinition::SchemaElements::EnumsForIndexedTypes
- Defined in:
- lib/elastic_graph/schema_definition/schema_elements/enums_for_indexed_types.rb
Overview
Responsible for generating enum types based on specific indexed types.
Instance Method Summary collapse
-
#initialize(schema_def_state) ⇒ EnumsForIndexedTypes
constructor
A new instance of EnumsForIndexedTypes.
-
#sort_order_enum_for(indexed_type) ⇒ Object
Generates a ‘SortOrder` enum type for the given indexed type.
Constructor Details
#initialize(schema_def_state) ⇒ EnumsForIndexedTypes
Returns a new instance of EnumsForIndexedTypes.
19 20 21 |
# File 'lib/elastic_graph/schema_definition/schema_elements/enums_for_indexed_types.rb', line 19 def initialize(schema_def_state) @schema_def_state = schema_def_state end |
Instance Method Details
#sort_order_enum_for(indexed_type) ⇒ Object
Generates a ‘SortOrder` enum type for the given indexed type.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/elastic_graph/schema_definition/schema_elements/enums_for_indexed_types.rb', line 24 def sort_order_enum_for(indexed_type) return nil unless indexed_type.indexed? build_enum(indexed_type, :sort_order, :sortable?, "sorted") do |enum_type, field_path| value_name_parts = field_path.map(&:name) index_field = field_path.map(&:name_in_index).join(".") {asc: "ascending", desc: "descending"}.each do |dir, dir_description| enum_type.value((value_name_parts + [dir.to_s.upcase]).join("_")) do |v| v. sort_field: SchemaArtifacts::RuntimeMetadata::SortField.new(index_field, dir) v.documentation "Sorts #{dir_description} by the `#{graphql_field_path_description(field_path)}` field." wrapped_enum_value = @schema_def_state.factory.new_sort_order_enum_value(v, field_path) field_path.each do |field| field.sort_order_enum_value_customizations.each { |block| block.call(wrapped_enum_value) } end end end end end |