Class: Lolita::Adapter::Mongoid::Field
- Includes:
- FieldHelper
- Defined in:
- lib/lolita/adapter/mongoid.rb
Overview
Each field from ORM is changed to this class instance.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #association ⇒ Object
-
#initialize(column, adapter) ⇒ Field
constructor
A new instance of Field.
- #method_missing(method, *args, &block) ⇒ Object
- #primary? ⇒ Boolean
Methods included from FieldHelper
Constructor Details
#initialize(column, adapter) ⇒ Field
Returns a new instance of Field.
69 70 71 72 73 74 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
90 91 92 |
# File 'lib/lolita/adapter/mongoid.rb', line 90 def method_missing(method,*args,&block) @field.send(method,*args,&block) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
68 69 70 |
# File 'lib/lolita/adapter/mongoid.rb', line 68 def adapter @adapter end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
68 69 70 |
# File 'lib/lolita/adapter/mongoid.rb', line 68 def field @field end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
68 69 70 |
# File 'lib/lolita/adapter/mongoid.rb', line 68 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
68 69 70 |
# File 'lib/lolita/adapter/mongoid.rb', line 68 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
68 69 70 |
# File 'lib/lolita/adapter/mongoid.rb', line 68 def type @type end |
Instance Method Details
#association ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 |
#primary? ⇒ Boolean
94 95 96 |
# File 'lib/lolita/adapter/mongoid.rb', line 94 def primary? !!self.[:primary] || @field.type.to_s =~ /ObjectId/ end |