module Fathom::AttributeSystem::ClassMethods
Public Instance Methods
attribute(getter_name, default=nil)
click to toggle source
Define an attribute, or property of this class. Useful for very thin, generic Ruby classes for Data models.
# File lib/fathom/behaviors/attribute_system.rb, line 40 def attribute(getter_name, default=nil) # Define a getter on the object define_method(getter_name) do target = send(self.class.attributes_proxy) return target[getter_name] unless target.respond_to?(:has_key?) if target.has_key?(getter_name) target[getter_name] else self.class.attribute_defaults[getter_name] end end # Define a setter on the object define_method("#{getter_name}=") do |value| send(self.class.attributes_proxy)[getter_name] = value end # Define a default on the object attribute_defaults[getter_name] = default end
attribute_defaults()
click to toggle source
# File lib/fathom/behaviors/attribute_system.rb, line 75 def attribute_defaults @attribute_defaults ||= {} end
attributes_proxy()
click to toggle source
# File lib/fathom/behaviors/attribute_system.rb, line 71 def attributes_proxy @attributes_proxy ||= :attributes end
set_attributes_proxy(value)
click to toggle source
Defines where the attributes are stored for the target class.
# File lib/fathom/behaviors/attribute_system.rb, line 67 def set_attributes_proxy(value) @attributes_proxy = value end