# File lib/lolita/adapter/mongoid.rb, line 94 def primary? !!self.options[:primary] || @field.type.to_s =~ /ObjectId/ end
class Lolita::Adapter::Mongoid::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/mongoid.rb, line 69 def initialize(column,adapter) @field = column raise ArgumentError, "Cannot initialize adapter field for nil" unless @field @adapter = adapter set_attributes end
Public Instance Methods
association()
click to toggle source
# File lib/lolita/adapter/mongoid.rb, line 76 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
method_missing(method,*args,&block)
click to toggle source
# File lib/lolita/adapter/mongoid.rb, line 90 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/mongoid.rb, line 110 def set_attributes @name = @field.name @type = type_cast(@field.type) @options = @field.options.merge({ :primary => @field.type.to_s == "BSON::ObjectId", :native_type => @field.type.to_s }) end
type_cast(type)
click to toggle source
# File lib/lolita/adapter/mongoid.rb, line 100 def type_cast(type) if type.to_s=="Object" || type.to_s.split("::").last == "Object" "string" elsif type.to_s.match(/::/) type.to_s.split("::").last else type.to_s.underscore end end