class RediSearch::Schema
Attributes
raw[RW]
Public Class Methods
make_field(field_name, options)
click to toggle source
# File lib/redi_search/schema.rb, line 10 def self.make_field(field_name, options) options = [options] if options.is_a? Symbol schema, options = options.to_a.flatten Object.const_get("RediSearch::Schema::#{schema.to_s.capitalize}Field"). new(field_name, **options.to_h) end
new(raw)
click to toggle source
# File lib/redi_search/schema.rb, line 18 def initialize(raw) @raw = raw end
Public Instance Methods
[](field)
click to toggle source
# File lib/redi_search/schema.rb, line 26 def [](field) fields.group_by(&:name)[field]&.first end
add_field(field_name, options)
click to toggle source
# File lib/redi_search/schema.rb, line 36 def add_field(field_name, options) raw[field_name] = options @fields = nil self end
fields()
click to toggle source
# File lib/redi_search/schema.rb, line 30 def fields @fields ||= raw.map do |field_name, options| self.class.make_field(field_name, options) end.flatten end
to_a()
click to toggle source
# File lib/redi_search/schema.rb, line 22 def to_a fields.map(&:to_a).flatten end