class Mugatu::Entity
Public Class Methods
attribute(key, type, options = {})
click to toggle source
# 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
attributes()
click to toggle source
# File lib/mugatu/entity.rb, line 12 def self.attributes @attributes ||= [] end
new(attributes = {})
click to toggle source
# 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
Private Class Methods
define_attribute_reader(attribute)
click to toggle source
# File lib/mugatu/entity.rb, line 28 def self.define_attribute_reader(attribute) define_method attribute.key do attribute.value end end
define_attribute_writer(attribute)
click to toggle source
# File lib/mugatu/entity.rb, line 34 def self.define_attribute_writer(attribute) define_method "#{attribute.key}=" do |value| attribute.value = value end end
Public Instance Methods
attributes()
click to toggle source
# File lib/mugatu/entity.rb, line 22 def attributes self.class.attributes end