Class: AttributesDSL::Attributes Private
- Inherits:
-
Object
- Object
- AttributesDSL::Attributes
- Defined in:
- lib/attributes_dsl/attributes.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Describes a collection of attributes declaration with methods to validate and extract instance attributes from a hash.
Instance Attribute Summary collapse
-
#attributes ⇒ Set
readonly
private
Uses the set of attributes to ensure their uniqueness (by name).
Instance Method Summary collapse
-
#add(name, options = {}, &coercer) ⇒ AttributesDSL::Attributes
private
Initializes the attribute from given arguments and returns new immutable collection with the attribute.
-
#reader?(name) ⇒ Boolean
private
Checks whether an attribute reader should be defined.
-
#transformer ⇒ Proc
private
Returns the proc that converts a hash of attributes using current setting.
Instance Attribute Details
#attributes ⇒ Set (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Uses the set of attributes to ensure their uniqueness (by name)
19 20 21 |
# File 'lib/attributes_dsl/attributes.rb', line 19 def attributes @attributes ||= {} end |
Instance Method Details
#add(name, options = {}, &coercer) ⇒ AttributesDSL::Attributes
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the attribute from given arguments and returns new immutable collection with the attribute
30 31 32 33 34 35 36 37 |
# File 'lib/attributes_dsl/attributes.rb', line 30 def add(name, = {}, &coercer) name = name.to_sym value = Attribute.new(name, , &coercer) clone_with do @attributes = attributes.merge(name => value) @transformer = nil end end |
#reader?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks whether an attribute reader should be defined
53 54 55 |
# File 'lib/attributes_dsl/attributes.rb', line 53 def reader?(name) attributes[name.to_sym].reader end |
#transformer ⇒ Proc
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the proc that converts a hash of attributes using current setting
43 44 45 |
# File 'lib/attributes_dsl/attributes.rb', line 43 def transformer @transformer ||= transprocs.flatten.compact.reduce(:>>) end |