Class: Base

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ma_accessor(*syms) ⇒ Object

Adapted from activesupport/lib/active_support/core_ext/module/attribute_accessors.rb


32
33
34
35
# File 'app/models/base.rb', line 32

def ma_accessor(*syms)
  ma_reader(*syms)
  ma_writer(*syms)
end

.ma_reader(*syms) ⇒ Object


37
38
39
40
41
42
43
44
45
46
# File 'app/models/base.rb', line 37

def ma_reader(*syms)
  options = syms.extract_options!
  syms.each do |sym|
    class_eval("
      def #{sym}
        more_attributes['#{sym}']
      end
  ", __FILE__, __LINE__ + 1)
  end
end

.ma_writer(*syms) ⇒ Object


48
49
50
51
52
53
54
55
56
57
# File 'app/models/base.rb', line 48

def ma_writer(*syms)
  options = syms.extract_options!
  syms.each do |sym|
    class_eval("
      def #{sym}=(obj)
        more_attributes['#{sym}'] = obj
      end
  ", __FILE__, __LINE__ + 1)
  end
end

Instance Method Details

#serialize_more_attributes(record = self) ⇒ Object (private)


24
25
26
27
28
# File 'app/models/base.rb', line 24

def serialize_more_attributes(record = self)
  if record.more_attributes && !record.more_attributes.is_a?(Hash)
    record.more_attributes = ActiveSupport::JSON.decode(record.more_attributes)
  end
end