Class: Redis::Commands::Search::Schema
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
Enumerable
|
|
| Inherits: | Object |
| Defined in: | lib/redis/commands/modules/search/schema.rb |
Overview
Class Method Summary
-
.build(&block) ⇒ Schema
Build a schema using the block DSL evaluated in a
SchemaDefinition. -
.new(fields = []) ⇒ Schema
constructor
Build a schema from a list of fields.
Instance Attribute Summary
- #fields readonly
Instance Method Summary
-
#each {|field| ... } ⇒ Enumerator, Array<Field>
Iterate over the schema's fields.
-
#field(name) ⇒ Field?
Find a field by its name/path or its
ASalias, so e.g. -
#to_args ⇒ Array
Render the schema as the array of
FT.CREATEtokens.
Constructor Details
.new(fields = []) ⇒ Schema
Build a schema from a list of fields.
Class Method Details
.build(&block) ⇒ Schema
Build a schema using the block DSL evaluated in a SchemaDefinition.
# File 'lib/redis/commands/modules/search/schema.rb', line 58
def self.build(&block) definition = SchemaDefinition.new begin definition.instance_eval(&block) rescue ArgumentError => e raise Redis::CommandError, e. end new(definition.fields) end
Instance Attribute Details
#fields (readonly)
[ GitHub ]# File 'lib/redis/commands/modules/search/schema.rb', line 11
attr_reader :fields
Instance Method Details
#each {|field| ... } ⇒ Enumerator, Array<Field>
Iterate over the schema's fields.
# File 'lib/redis/commands/modules/search/schema.rb', line 34
def each(&block) @fields.each(&block) end
#field(name) ⇒ Field?
Find a field by its name/path or its AS alias, so e.g. a JSON field declared as
"$.price" AS "price" is found by either "$.price" or "price".
# File 'lib/redis/commands/modules/search/schema.rb', line 25
def field(name) name = name.to_s @fields.find { |f| f.name.to_s == name || f.alias_name&.to_s == name } end
#to_args ⇒ Array
Render the schema as the array of FT.CREATE tokens.
# File 'lib/redis/commands/modules/search/schema.rb', line 44
def to_args ['SCHEMA'] + @fields.flat_map(&:to_args) end