Module: Toy::Attributes::ClassMethods

Defined in:
lib/toy/attributes.rb

Instance Method Summary collapse

Instance Method Details

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



26
27
28
29
30
31
# File 'lib/toy/attributes.rb', line 26

def attribute(key, type, options = {})
  @defaulted_attributes = nil
  attribute = Attribute.new(self, key, type, options)
  define_attribute_methods [attribute.name]
  attribute
end

#attribute?(key) ⇒ Boolean

Returns:



33
34
35
# File 'lib/toy/attributes.rb', line 33

def attribute?(key)
  attributes.has_key?(key.to_s)
end

#attributesObject



18
19
20
# File 'lib/toy/attributes.rb', line 18

def attributes
  @attributes ||= {}
end

#defaulted_attributesObject



22
23
24
# File 'lib/toy/attributes.rb', line 22

def defaulted_attributes
  @defaulted_attributes ||= attributes.values.select(&:default?)
end