Class: RSchema::Schemas::Maybe
- Inherits:
-
Object
- Object
- RSchema::Schemas::Maybe
- Defined in:
- lib/rschema/schemas/maybe.rb
Overview
A schema representing that a value may be ‘nil`
If the value is not ‘nil`, it must conform to the subschema
Instance Attribute Summary collapse
-
#subschema ⇒ Object
readonly
Returns the value of attribute subschema.
Instance Method Summary collapse
- #call(value, options) ⇒ Object
-
#initialize(subschema) ⇒ Maybe
constructor
A new instance of Maybe.
- #with_wrapped_subschemas(wrapper) ⇒ Object
Constructor Details
#initialize(subschema) ⇒ Maybe
Returns a new instance of Maybe.
17 18 19 |
# File 'lib/rschema/schemas/maybe.rb', line 17 def initialize(subschema) @subschema = subschema end |
Instance Attribute Details
#subschema ⇒ Object (readonly)
Returns the value of attribute subschema.
15 16 17 |
# File 'lib/rschema/schemas/maybe.rb', line 15 def subschema @subschema end |
Instance Method Details
#call(value, options) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rschema/schemas/maybe.rb', line 21 def call(value, ) if nil == value Result.success(value) else @subschema.call(value, ) end end |
#with_wrapped_subschemas(wrapper) ⇒ Object
29 30 31 |
# File 'lib/rschema/schemas/maybe.rb', line 29 def with_wrapped_subschemas(wrapper) self.class.new(wrapper.wrap(subschema)) end |