Class: RediSearch::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/redi_search/schema.rb,
lib/redi_search/schema/field.rb,
lib/redi_search/schema/geo_field.rb,
lib/redi_search/schema/tag_field.rb,
lib/redi_search/schema/text_field.rb,
lib/redi_search/schema/numeric_field.rb

Defined Under Namespace

Classes: Field, GeoField, NumericField, TagField, TextField

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Schema

Returns a new instance of Schema.



7
8
9
10
11
# File 'lib/redi_search/schema.rb', line 7

def initialize(&block)
  @fields = []

  instance_exec(&block)
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



5
6
7
# File 'lib/redi_search/schema.rb', line 5

def fields
  @fields
end

Instance Method Details

#[](name) ⇒ Object



42
43
44
# File 'lib/redi_search/schema.rb', line 42

def [](name)
  fields.find { |field| field.name.to_sym == name.to_sym }
end

#add_field(name, type) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/redi_search/schema.rb', line 29

def add_field(name, type, ...)
  case type
  when :text then method(:text_field)
  when :numeric then method(:numeric_field)
  when :tag then method(:tag_field)
  when :geo then method(:geo_field)
  end.call(name, ...)
end

#geo_field(name) ⇒ Object



25
26
27
# File 'lib/redi_search/schema.rb', line 25

def geo_field(name, ...)
  self[name] || push(Schema::GeoField.new(name, ...))
end

#numeric_field(name) ⇒ Object



17
18
19
# File 'lib/redi_search/schema.rb', line 17

def numeric_field(name, ...)
  self[name] || push(Schema::NumericField.new(name, ...))
end

#tag_field(name) ⇒ Object



21
22
23
# File 'lib/redi_search/schema.rb', line 21

def tag_field(name, ...)
  self[name] || push(Schema::TagField.new(name, ...))
end

#text_field(name) ⇒ Object



13
14
15
# File 'lib/redi_search/schema.rb', line 13

def text_field(name, ...)
  self[name] || push(Schema::TextField.new(name, ...))
end

#to_aObject



38
39
40
# File 'lib/redi_search/schema.rb', line 38

def to_a
  fields.map(&:to_a).flatten
end