module Seria::InfoTable
Public Class Methods
define_info_table(class_name)
click to toggle source
# File lib/seria/info_table.rb, line 59 def self.define_info_table(class_name) unless defined?(class_name) && class_name.is_a?(Class) Object.const_set class_name, Class.new(ActiveRecord::Base) end klass = class_name.constantize klass.send(:include, Seria::InfoTable) unless klass.include? Seria::InfoTable if Rails.version =~ /^3/ klass.send(:attr_accessible, *(Seria.config.fields.marshal_dump.values)) end end
Public Instance Methods
convert()
click to toggle source
# File lib/seria/info_table.rb, line 19 def convert converter.convert end
converter()
click to toggle source
# File lib/seria/info_table.rb, line 27 def converter (converters[field_name] || converters[field_type] || DefaultConverter).new( read_attribute(Seria.config.fields.value), read_attribute(Seria.config.fields.type)) end
converters()
click to toggle source
# File lib/seria/info_table.rb, line 23 def converters Seria.config.converters || {} end
field_name()
click to toggle source
# File lib/seria/info_table.rb, line 35 def field_name read_attribute Seria.config.fields.key end
field_type()
click to toggle source
# File lib/seria/info_table.rb, line 42 def field_type read_attribute(Seria.config.fields.type) end
field_type=(val)
click to toggle source
# File lib/seria/info_table.rb, line 45 def field_type=(val) write_attribute(Seria.config.fields.type, val) end
field_value()
click to toggle source
# File lib/seria/info_table.rb, line 39 def field_value convert end
field_value=(val)
click to toggle source
# File lib/seria/info_table.rb, line 48 def field_value=(val) write_attribute(Seria.config.fields.value, val) end
to_db()
click to toggle source
# File lib/seria/info_table.rb, line 52 def to_db self.field_value = convert #force cast back from varchar in case not a new entry self.field_type = read_attribute(Seria.config.fields.value).class.to_s self.field_value = converter.to_db true end