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
25
26
27
28
29
30
# File 'lib/hashed_attributes.rb', line 8

def hashed_attributes name, *options
  include InstanceMethods

  serialize name.to_sym, Hash

  options.each do |n|
    define_method "#{n}" do
      get_hashed_attribute_for(n)
    end

    define_method "#{n}=" do |arg|
      set_hashed_attribute_for(n,arg)
    end
  end

  define_method "hashed_attributes_column" do
    name
  end

  self.after_initialize do
    initialize_hashed_attributes
  end
end