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.
18 19 20 |
# File 'lib/rschema/schemas/maybe.rb', line 18 def initialize(subschema) @subschema = subschema end |
Instance Attribute Details
#subschema ⇒ Object (readonly)
Returns the value of attribute subschema.
16 17 18 |
# File 'lib/rschema/schemas/maybe.rb', line 16 def subschema @subschema end |
Instance Method Details
#call(value, options) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rschema/schemas/maybe.rb', line 22 def call(value, ) if value.nil? Result.success(value) else @subschema.call(value, ) end end |
#with_wrapped_subschemas(wrapper) ⇒ Object
30 31 32 |
# File 'lib/rschema/schemas/maybe.rb', line 30 def with_wrapped_subschemas(wrapper) self.class.new(wrapper.wrap(subschema)) end |