Module: IndexableAttribute::ClassMethods

Defined in:
lib/indexable_attribute.rb

Instance Method Summary collapse

Instance Method Details

#indexable_attribute(attr_name, attr_list) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/indexable_attribute.rb', line 8

def indexable_attribute(attr_name, attr_list)
	_CNST = attr_name.to_s.upcase
	_ATTR = attr_name.to_s.downcase
  class_eval %Q{
  	#{_CNST} = #{attr_list.map { |i| i.to_sym }.to_s}

			def #{_ATTR}
				#{_CNST}[self[:#{_ATTR}_id]]
			end

			def #{_ATTR}=(v)
				self[:#{_ATTR}_id] = #{_CNST}.index(v.to_sym)
			end
	    }
end