Class: Mugatu::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/mugatu/entity.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Entity

Returns a new instance of Entity.



16
17
18
19
20
# File 'lib/mugatu/entity.rb', line 16

def initialize(attributes = {})
  self.attributes.each do |a|
    send("#{a.key}=", attributes[a.key]) if attributes.key?(a.key)
  end
end

Class Method Details

.attribute(key, type, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/mugatu/entity.rb', line 3

def self.attribute(key, type, options = {})
  attribute = Attribute.new(key, type, options)

  define_attribute_reader(attribute)
  define_attribute_writer(attribute)

  attributes << attribute
end

.attributesObject



12
13
14
# File 'lib/mugatu/entity.rb', line 12

def self.attributes
  @attributes ||= []
end

Instance Method Details

#attributesObject



22
23
24
# File 'lib/mugatu/entity.rb', line 22

def attributes
  self.class.attributes
end