Class: Kojn::Model

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Model, ActiveModel::Validations
Included in:
Tx
Defined in:
lib/kojn/model.rb

Direct Known Subclasses

Invoice

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Model

Returns a new instance of Model.



8
9
10
# File 'lib/kojn/model.rb', line 8

def initialize(attributes = {})
  self.attributes = attributes
end

Instance Method Details

#attributesObject

Returns a hash with the current instance variables



27
28
29
# File 'lib/kojn/model.rb', line 27

def attributes
  Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
end

#attributes=(attributes = {}) ⇒ Object

Set the attributes based on the given hash



16
17
18
19
20
21
22
23
24
# File 'lib/kojn/model.rb', line 16

def attributes=(attributes = {})
  attributes.each do |name, value|
    begin
      send("#{name}=", value)
    rescue NoMethodError => e
      puts "Unable to assign #{name}. No such method."
    end
  end
end