Module: Opto::Model::Initializer

Defined in:
lib/opto/model/initializer.rb

Instance Method Summary collapse

Instance Method Details

#assign(attributes) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/opto/model/initializer.rb', line 20

def assign(attributes)
  attributes.each do |key, value|
    if self.respond_to?("#{key}=")
      self.send("#{key}=", value)
    else
      raise ArgumentError, "Unknown attribute '#{key}'"
    end
  end
end

#collectionObject



16
17
18
# File 'lib/opto/model/initializer.rb', line 16

def collection
  @collection
end

#initialize(attributes = {}) ⇒ Object



7
8
9
10
# File 'lib/opto/model/initializer.rb', line 7

def initialize(attributes = {})
  initialize_collection
  assign(attributes)
end

#initialize_collectionObject



12
13
14
# File 'lib/opto/model/initializer.rb', line 12

def initialize_collection
  @collection = AttributeCollection.new(self.class.attribute_definitions)
end