# File lib/lolita/adapter/active_record.rb, line 113 def primary? !!self.options[:primary] end
class Lolita::Adapter::ActiveRecord::Field
Each field from ORM is changed to this class instance.
Attributes
adapter[R]
field[R]
name[R]
options[R]
type[R]
Public Class Methods
new(column,adapter)
click to toggle source
# File lib/lolita/adapter/active_record.rb, line 84 def initialize(column,adapter) @field = column raise ArgumentError, "Cannot initialize adapter field for nil" unless @field @adapter = adapter set_attributes end
types()
click to toggle source
# File lib/lolita/adapter/active_record.rb, line 117 def self.types { 'decimal' => 'big_decimal', 'datetime' => 'date_time', 'text' => 'string' } end
Public Instance Methods
association()
click to toggle source
# File lib/lolita/adapter/active_record.rb, line 91 def association if @association.nil? possible_association = @adapter.associations.detect{|name,association| [association.key.to_s].include?(@name.to_s) } @association = if possible_association possible_association.last else false end end @association end
key()
click to toggle source
# File lib/lolita/adapter/active_record.rb, line 105 def key @association.foreign_association_key end
method_missing(method,*args,&block)
click to toggle source
# File lib/lolita/adapter/active_record.rb, line 109 def method_missing(method,*args,&block) @field.send(method,*args,&block) end
primary?()
click to toggle source
Private Instance Methods
set_attributes()
click to toggle source
# File lib/lolita/adapter/active_record.rb, line 127 def set_attributes @name = @field.name @type = type_cast(@field.type) @options = { :primary => @field.name.ends_with?('_id'), :native_type => @field.type.to_s } end
type_cast(type_name)
click to toggle source
# File lib/lolita/adapter/active_record.rb, line 136 def type_cast type_name type = self.class.types[type_name.to_s] || type_name.to_s if self.association type = "array" end type end