module SerializedAttributes::ClassMethods
Public Instance Methods
accessible_attribute(name, type, opts = {})
click to toggle source
# File lib/serialized_attributes.rb, line 30 def accessible_attribute(name, type, opts = {}) attribute(name, type, opts.merge({:attr_accessible => true})) end
attribute(name, type, opts = {})
click to toggle source
# File lib/serialized_attributes.rb, line 34 def attribute(name, type, opts = {}) name = name.to_s type = SerializedAttributes.type_to_sqltype(type) serialized_attributes_definition[name] = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, opts[:default], type.to_s, nil) define_method("#{name.to_s}=".to_sym) { |value| @attributes[name] = value } define_method(name) { self.class.serialized_attributes_definition[name].type_cast(@attributes[name]) } attr_accessible name if opts[:attr_accessible] end
instantiate(record)
click to toggle source
Calls superclass method
# File lib/serialized_attributes.rb, line 24 def instantiate(record) object = super(record) object.unpack_serialized_attributes! object end
serialized_attributes_definition()
click to toggle source
# File lib/serialized_attributes.rb, line 20 def serialized_attributes_definition read_inheritable_attribute(:serialized_attributes_definition) end