module ScientificProtocols::Resources::Object::Attributes::ClassMethods

Public Instance Methods

attribute(name, type = String) click to toggle source
# File lib/scientificprotocols/resources/object/attributes.rb, line 26
def attribute(name, type = String)
  attributes[name] = type

  define_attribute_accessor(name, type)
end
Also aliased as: has_many
attributes() click to toggle source
# File lib/scientificprotocols/resources/object/attributes.rb, line 3
def attributes
  @attributes ||=
    begin
      if superclass.respond_to?(:attributes)
        superclass.attributes.dup
      else
        Hash.new { |hash, key| hash[key] = ::Object }
      end
    end
end
attributes_module() click to toggle source

@return [Module] module holding all attribute accessors

# File lib/scientificprotocols/resources/object/attributes.rb, line 15
def attributes_module
  @attributes_module ||= const_set(:AttributeMethods, Module.new)
end
define_attribute_accessor(name, type = nil) click to toggle source
# File lib/scientificprotocols/resources/object/attributes.rb, line 19
def define_attribute_accessor(name, type = nil)
  type ||= attributes[name.to_sym] || Object
  attributes_module.send(:define_method, name) do
    deserialize_attribute(name, type)
  end
end
has_many(name, type = String)
Alias for: attribute