Class: Dry::Schema::Macros::Maybe
- Defined in:
- lib/dry/schema/macros/maybe.rb
Overview
Macro used to specify predicates for a value that can be ‘nil`
Instance Method Summary collapse
- #call(*args, **opts, &block) ⇒ Object private
- #to_ast ⇒ Object private
Methods inherited from DSL
#array, #each, #filled, #hash, #schema, #value
Methods inherited from Core
Instance Method Details
#call(*args, **opts, &block) ⇒ 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.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dry/schema/macros/maybe.rb', line 13 def call(*args, **opts, &block) if args.include?(:empty?) raise ::Dry::Schema::InvalidSchemaError, 'Using maybe with empty? predicate is invalid' end if args.include?(:nil?) raise ::Dry::Schema::InvalidSchemaError, 'Using maybe with nil? predicate is redundant' end value(*args, **opts, &block) self end |
#to_ast ⇒ 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.
28 29 30 31 32 33 34 35 |
# File 'lib/dry/schema/macros/maybe.rb', line 28 def to_ast [:implication, [ [:not, [:predicate, [:nil?, [[:input, Undefined]]]]], trace.to_rule.to_ast ] ] end |