Class: AttributesDSL::Attribute Private
- Inherits:
-
Object
- Object
- AttributesDSL::Attribute
- Defined in:
- lib/attributes_dsl/attribute.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 settings for PORO attribute
Instance Attribute Summary collapse
-
#coercer ⇒ Proc?
readonly
private
The coercer for the attribute.
-
#default ⇒ Object
readonly
private
The default value of the attribute.
-
#name ⇒ Symbol
readonly
private
The name of the attribute.
-
#required ⇒ Boolean
readonly
private
Whether the attribute is required.
Instance Method Summary collapse
-
#initialize(name, options = {}, &coercer) ⇒ Attribute
constructor
private
Initializes the attribute.
-
#value(input) ⇒ Object
private
Coerces an input assigned to the attribute.
Constructor Details
#initialize(name, options = {}, &coercer) ⇒ Attribute
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
48 49 50 51 52 53 54 55 |
# File 'lib/attributes_dsl/attribute.rb', line 48 def initialize(name, = {}, &coercer) @name = name @default = .fetch(:default) {} @required = default.nil? && .fetch(:required) { false } @coercer = coercer IceNine.deep_freeze(self) end |
Instance Attribute Details
#coercer ⇒ Proc? (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.
Returns the coercer for the attribute.
37 38 39 |
# File 'lib/attributes_dsl/attribute.rb', line 37 def coercer @coercer end |
#default ⇒ Object (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.
Returns the default value of the attribute.
25 26 27 |
# File 'lib/attributes_dsl/attribute.rb', line 25 def default @default end |
#name ⇒ Symbol (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.
Returns the name of the attribute.
19 20 21 |
# File 'lib/attributes_dsl/attribute.rb', line 19 def name @name end |
#required ⇒ Boolean (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.
Returns whether the attribute is required.
31 32 33 |
# File 'lib/attributes_dsl/attribute.rb', line 31 def required @required end |
Instance Method Details
#value(input) ⇒ Object
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.
Coerces an input assigned to the attribute
63 64 65 |
# File 'lib/attributes_dsl/attribute.rb', line 63 def value(input) coercer ? coercer[input] : input end |