Class: BettyResource::Model::Property

Inherits:
Object
  • Object
show all
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,
lib/betty_resource/model/property/types/has_and_belongs_to_many.rb

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from KindExtendable

included

Constructor Details

#initialize(id, model_id, name, kind, options) ⇒ Property

Returns a new instance of Property.



21
22
23
24
# File 'lib/betty_resource/model/property.rb', line 21

def initialize(id, model_id, name, kind, options)
  @id, @model_id, @name, @kind, @options = id, model_id, name, kind, options
  extend_kind_methods if %(belongs_to has_and_belongs_to_many has_many).include?(kind)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/betty_resource/model/property.rb', line 10

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



10
11
12
# File 'lib/betty_resource/model/property.rb', line 10

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/betty_resource/model/property.rb', line 10

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/betty_resource/model/property.rb', line 10

def options
  @options
end

Class Method Details

.parse(model_id, input) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/betty_resource/model/property.rb', line 12

def self.parse(model_id, input)
  input.map do |row|
    options = row['options']
    inverse_association = row["inverse_association"]
    options.merge!("inverse_association" => inverse_association) if inverse_association
    Property.new(row['id'], model_id, row['name'], row['kind'], options)
  end
end

Instance Method Details

#collection?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/betty_resource/model/property.rb', line 26

def collection?
  false
end

#modelObject



34
35
36
# File 'lib/betty_resource/model/property.rb', line 34

def model
  @model ||= BettyResource..models.values.find { |x| x.id == @model_id }
end

#typecast(record, value) ⇒ Object



30
31
32
# File 'lib/betty_resource/model/property.rb', line 30

def typecast(record, value)
  value
end