Class: Icalia::ModelBase

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ResourceIdentity
Defined in:
lib/icalia/models/model_base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ResourceIdentity

#to_key

Constructor Details

#initialize(object_attributes = {}) ⇒ ModelBase

Returns a new instance of ModelBase.



15
16
17
18
19
20
21
22
23
24
# File 'lib/icalia/models/model_base.rb', line 15

def initialize(object_attributes = {})
  @serialization_context = object_attributes.delete :serialization_context
  
  object_attributes.each do |key, value|
    attribute_name = "#{key}".underscore
    next register_stand_in(attribute_name, value) if value.is_a? ModelProxy
    next register_collection(attribute_name, value) if value.is_a? Array
    instance_variable_set("@#{attribute_name}", value)
  end
end

Instance Attribute Details

#serialization_contextObject (readonly)

Returns the value of attribute serialization_context.



10
11
12
# File 'lib/icalia/models/model_base.rb', line 10

def serialization_context
  @serialization_context
end

Class Method Details

.has_many(*associations) ⇒ Object



34
35
36
37
38
39
# File 'lib/icalia/models/model_base.rb', line 34

def has_many(*associations)
  associations.each do |association|
    attr_reader association
    associated_resource_collections << association
  end
end

.has_one(*associations) ⇒ Object



27
28
29
30
31
32
# File 'lib/icalia/models/model_base.rb', line 27

def has_one(*associations)
  associations.each do |association|
    attr_reader association
    associated_resources << association
  end
end