Class: Lolita::Adapter::ActiveRecord::Field
- Includes:
- FieldHelper
- Defined in:
- lib/lolita/adapter/active_record.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.
Class Method Summary collapse
Instance Method Summary collapse
- #association ⇒ Object
-
#initialize(column, adapter) ⇒ Field
constructor
A new instance of Field.
- #key ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #primary? ⇒ Boolean
Methods included from FieldHelper
Constructor Details
#initialize(column, adapter) ⇒ Field
Returns a new instance of Field.
84 85 86 87 88 89 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
109 110 111 |
# File 'lib/lolita/adapter/active_record.rb', line 109 def method_missing(method,*args,&block) @field.send(method,*args,&block) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
83 84 85 |
# File 'lib/lolita/adapter/active_record.rb', line 83 def adapter @adapter end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
83 84 85 |
# File 'lib/lolita/adapter/active_record.rb', line 83 def field @field end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
83 84 85 |
# File 'lib/lolita/adapter/active_record.rb', line 83 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
83 84 85 |
# File 'lib/lolita/adapter/active_record.rb', line 83 def @options end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
83 84 85 |
# File 'lib/lolita/adapter/active_record.rb', line 83 def type @type end |
Class Method Details
.types ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/lolita/adapter/active_record.rb', line 117 def self.types { 'decimal' => 'big_decimal', 'datetime' => 'date_time', 'text' => 'string' } end |
Instance Method Details
#association ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# 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 ⇒ Object
105 106 107 |
# File 'lib/lolita/adapter/active_record.rb', line 105 def key @association.foreign_association_key end |
#primary? ⇒ Boolean
113 114 115 |
# File 'lib/lolita/adapter/active_record.rb', line 113 def primary? !!self.[:primary] end |