Module: Bronze::Entities::Attributes::ClassMethods
- Defined in:
- lib/bronze/entities/attributes.rb
Overview
Class methods to define when including Attributes in a class.
Instance Method Summary collapse
-
#attribute(attribute_name, attribute_type, attribute_options = {}) ⇒ Attributes::Metadata
Defines an attribute with the specified name and type.
-
#attributes ⇒ Hash{Symbol => Attributes::Metadata}
Returns the metadata for the attributes defined for the current class.
- #each_attribute ⇒ Object
Instance Method Details
#attribute(attribute_name, attribute_type, attribute_options = {}) ⇒ Attributes::Metadata
Defines an attribute with the specified name and type.
38 39 40 41 42 43 |
# File 'lib/bronze/entities/attributes.rb', line 38 def attribute(attribute_name, attribute_type, = {}) = build_attribute(attribute_name, attribute_type, ) (@attributes ||= {})[.name] = end |
#attributes ⇒ Hash{Symbol => Attributes::Metadata}
Note:
This method allocates a new hash each time it is called and is not cached. To loop through the attributes, use the ::each_attribute method instead.
Returns the metadata for the attributes defined for the current class.
53 54 55 56 57 58 59 |
# File 'lib/bronze/entities/attributes.rb', line 53 def attributes each_attribute .with_object({}) do |(name, ), hsh| hsh[name] = end .freeze end |
#each_attribute ⇒ Enumerator #each_attribute {|name, name| ... } ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/bronze/entities/attributes.rb', line 75 def each_attribute return enum_for(:each_attribute) unless block_given? if superclass.respond_to?(:each_attribute) superclass.each_attribute { |name, | yield(name, ) } end (@attributes ||= {}).each { |name, | yield(name, ) } end |