Module: AttributeBuilder::ClassMethods

Defined in:
lib/redisant/attribute_builder.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/redisant/attribute_builder.rb', line 7

def attribute name, options={}
  attributes[name.to_s] = options

  if options[:index]
    index name, type: options[:index]     # add index for attribute
  end

  if options[:search] || options[:unique]
    finder name, type: options[:search]   # add search for attribute
  end

  send :define_method, name.to_s do
    attribute(name.to_s)
  end

  send :define_method, "#{name.to_s}=" do |value|
    set_attribute(name.to_s, value)
  end

end

#attributesObject



32
33
34
# File 'lib/redisant/attribute_builder.rb', line 32

def attributes
  @attributes ||= {}
end

#find_attribute(name) ⇒ Object



28
29
30
# File 'lib/redisant/attribute_builder.rb', line 28

def find_attribute name
  indexes[name.to_s]
end