Class: BettyResource::Model::Property
- Inherits:
-
Object
- Object
- BettyResource::Model::Property
- Includes:
- KindExtendable
- Defined in:
- lib/betty_resource/model/property.rb,
lib/betty_resource/model/property/types/has_many.rb,
lib/betty_resource/model/property/types/belongs_to.rb,
lib/betty_resource/model/property/types/association.rb
Defined Under Namespace
Modules: Types
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #collection? ⇒ Boolean
-
#initialize(id, model_id, name, kind, options) ⇒ Property
constructor
A new instance of Property.
- #model ⇒ Object
- #typecast(record, value) ⇒ Object
Methods included from KindExtendable
Constructor Details
#initialize(id, model_id, name, kind, options) ⇒ Property
Returns a new instance of Property.
20 21 22 23 |
# File 'lib/betty_resource/model/property.rb', line 20 def initialize(id, model_id, name, kind, ) @id, @model_id, @name, @kind, @options = id, model_id, name, kind, extend_kind_methods if %(belongs_to has_many).include?(kind) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/betty_resource/model/property.rb', line 9 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
9 10 11 |
# File 'lib/betty_resource/model/property.rb', line 9 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/betty_resource/model/property.rb', line 9 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/betty_resource/model/property.rb', line 9 def @options end |
Class Method Details
.parse(model_id, input) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/betty_resource/model/property.rb', line 11 def self.parse(model_id, input) input.map do |row| = row['options'] inverse_association = row["inverse_association"] .merge!("inverse_association" => inverse_association) if inverse_association Property.new(row['id'], model_id, row['name'], row['kind'], ) end end |
Instance Method Details
#collection? ⇒ Boolean
25 26 27 |
# File 'lib/betty_resource/model/property.rb', line 25 def collection? false end |
#model ⇒ Object
33 34 35 |
# File 'lib/betty_resource/model/property.rb', line 33 def model @model ||= BettyResource..models.values.find { |x| x.id == @model_id } end |
#typecast(record, value) ⇒ Object
29 30 31 |
# File 'lib/betty_resource/model/property.rb', line 29 def typecast(record, value) value end |