Class: TypesenseModel::Schema
- Inherits:
-
Object
- Object
- TypesenseModel::Schema
- Defined in:
- lib/typesense_model/schema.rb
Instance Attribute Summary collapse
-
#collection_name ⇒ Object
readonly
Returns the value of attribute collection_name.
-
#default_sorting_field ⇒ Object
readonly
Returns the value of attribute default_sorting_field.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #field(name, type, options = {}) ⇒ Object
-
#initialize(collection_name = nil) ⇒ Schema
constructor
A new instance of Schema.
- #to_hash ⇒ Object
Constructor Details
#initialize(collection_name = nil) ⇒ Schema
Returns a new instance of Schema.
7 8 9 10 11 |
# File 'lib/typesense_model/schema.rb', line 7 def initialize(collection_name = nil) @fields = [] @collection_name = collection_name @default_sorting_field = nil end |
Instance Attribute Details
#collection_name ⇒ Object (readonly)
Returns the value of attribute collection_name.
5 6 7 |
# File 'lib/typesense_model/schema.rb', line 5 def collection_name @collection_name end |
#default_sorting_field ⇒ Object (readonly)
Returns the value of attribute default_sorting_field.
5 6 7 |
# File 'lib/typesense_model/schema.rb', line 5 def default_sorting_field @default_sorting_field end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
5 6 7 |
# File 'lib/typesense_model/schema.rb', line 5 def fields @fields end |
Instance Method Details
#field(name, type, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/typesense_model/schema.rb', line 13 def field(name, type, = {}) @fields << { name: name.to_s, type: type.to_s, facet: [:facet] || false, optional: [:optional] || false, index: [:index].nil? ? true : [:index], sort: [:sort] || false } # Set as default sorting field if specified @default_sorting_field = name.to_s if [:default_sort] end |
#to_hash ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/typesense_model/schema.rb', line 27 def to_hash { name: @collection_name, fields: @fields, default_sorting_field: @default_sorting_field }.compact end |