Class: NestedStruct::Field
- Inherits:
-
Object
- Object
- NestedStruct::Field
- Defined in:
- lib/nested_struct/field.rb
Instance Attribute Summary collapse
-
#coercer ⇒ Object
readonly
Returns the value of attribute coercer.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #coerced? ⇒ Boolean
-
#initialize(name, coercer_expression = nil) ⇒ Field
constructor
A new instance of Field.
- #with(value) ⇒ Object
Constructor Details
Instance Attribute Details
#coercer ⇒ Object (readonly)
Returns the value of attribute coercer.
3 4 5 |
# File 'lib/nested_struct/field.rb', line 3 def coercer @coercer end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/nested_struct/field.rb', line 3 def name @name end |
Instance Method Details
#coerced? ⇒ Boolean
17 18 19 |
# File 'lib/nested_struct/field.rb', line 17 def coerced? !coercer.nil? end |
#with(value) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/nested_struct/field.rb', line 10 def with(value) return value if value.nil? return value if value.is_a?(NestedStruct::Empty) return value if !coerced? coercer.coerce(value) end |