Module: HashedAttributes::ClassMethods

Defined in:
lib/hashed_attributes.rb

Instance Method Summary collapse

Instance Method Details

#hashed_attributes(name, *options) ⇒ Object



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

def hashed_attributes name, *options
  include InstanceMethods

  serialize name, Hash

  options.each { |key|
    define_method(key) { get_hashed_attribute_for(key) }
    define_method("#{key}=") { |value| set_hashed_attribute_for(key,value) }
  }

  define_method("hashed_attributes_column") { name }
  define_method("hashed_attributes_keys") { options }

  self.after_initialize do
    initialize_hashed_attributes
  end
end