Class: Dry::Schema::Macros::Maybe Private
- Defined in:
- lib/dry/schema/macros/maybe.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.
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
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.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dry/schema/macros/maybe.rb', line 11 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 append_macro(Macros::Value) do |macro| macro.call(*args, **opts, &block) end 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 |
# File 'lib/dry/schema/macros/maybe.rb', line 28 def to_ast [:implication, [ [:not, [:predicate, [:nil?, [[:input, Undefined]]]]], trace.to_rule.to_ast ]] end |