Class: MotionModel::Model::Column
- Inherits:
-
Object
- Object
- MotionModel::Model::Column
- Defined in:
- lib/motion_model/model/column.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#destroy ⇒ Object
Returns the value of attribute destroy.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #classify ⇒ Object
-
#initialize(name = nil, type = nil, options = {}) ⇒ Column
constructor
A new instance of Column.
- #options ⇒ Object
Constructor Details
#initialize(name = nil, type = nil, options = {}) ⇒ Column
Returns a new instance of Column.
9 10 11 12 13 14 15 16 |
# File 'lib/motion_model/model/column.rb', line 9 def initialize(name = nil, type = nil, = {}) @name = name @type = type raise RuntimeError.new "columns need a type declared." if type.nil? @default = .delete :default @destroy = .delete :dependent @options = end |
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
6 7 8 |
# File 'lib/motion_model/model/column.rb', line 6 def default @default end |
#destroy ⇒ Object
Returns the value of attribute destroy.
7 8 9 |
# File 'lib/motion_model/model/column.rb', line 7 def destroy @destroy end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/motion_model/model/column.rb', line 4 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/motion_model/model/column.rb', line 5 def type @type end |
Instance Method Details
#classify ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/motion_model/model/column.rb', line 22 def classify case @type when :belongs_to @klass ||= Object.const_get(@name.to_s.camelize) when :has_many @klass ||= Object.const_get(@name.to_s.singularize.camelize) else raise "#{@name} is not a relation. This isn't supposed to happen." end end |
#options ⇒ Object
18 19 20 |
# File 'lib/motion_model/model/column.rb', line 18 def @options end |