Module: ActiveRecord::MagicMetaMethods::ClassMethods

Defined in:
lib/magic_meta_methods.rb

Instance Method Summary collapse

Instance Method Details

#magic_meta_methods(methods = [], options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/magic_meta_methods.rb', line 15

def magic_meta_methods(methods=[], options={})
    
  column_name = options[:column].blank? ? :magic_meta_methods : options[:column].to_sym
  self.meta_methods_column = column_name
  self.meta_methods_declarations = methods
  self.meta_methods_declarations.each do |attribute|
    if attribute.is_a?(Array)
      name = attribute[0]
      type = attribute[1]
    else
      #default to string since its the most common usage
      name = attribute
      type = :string
    end

    serialize column_name
    define_method(name.to_sym) { self.get_meta_value(name, type)}
    define_method((name.to_s + '=').to_sym) {|val| self.set_meta_value(name, val, type)}
  end
end