Class: Dry::Schema::Predicate
- Inherits:
-
Object
- Object
- Dry::Schema::Predicate
- Includes:
- Logic::Operators
- Defined in:
- lib/dry/schema/predicate.rb
Overview
Predicate objects used within the DSL
Defined Under Namespace
Classes: Negation
Instance Attribute Summary collapse
- #args ⇒ Object readonly private
- #block ⇒ Object readonly private
- #compiler ⇒ Object readonly private
- #name ⇒ Object readonly private
Instance Method Summary collapse
-
#! ⇒ Negation
Negate a predicate.
- #ensure_valid ⇒ Object private
-
#initialize(compiler, name, args, block) ⇒ Predicate
constructor
private
A new instance of Predicate.
-
#to_ast ⇒ Array
(also: #ast)
private
Dump predicate to an AST.
-
#to_rule ⇒ Object
private
Compile predicate to a rule object.
Constructor Details
#initialize(compiler, name, args, block) ⇒ Predicate
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.
Returns a new instance of Predicate.
53 54 55 56 57 58 |
# File 'lib/dry/schema/predicate.rb', line 53 def initialize(compiler, name, args, block) @compiler = compiler @name = name @args = args @block = block end |
Instance Attribute Details
#args ⇒ Object (readonly)
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.
47 48 49 |
# File 'lib/dry/schema/predicate.rb', line 47 def args @args end |
#block ⇒ Object (readonly)
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.
50 51 52 |
# File 'lib/dry/schema/predicate.rb', line 50 def block @block end |
#compiler ⇒ Object (readonly)
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.
41 42 43 |
# File 'lib/dry/schema/predicate.rb', line 41 def compiler @compiler end |
#name ⇒ Object (readonly)
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.
44 45 46 |
# File 'lib/dry/schema/predicate.rb', line 44 def name @name end |
Instance Method Details
#! ⇒ Negation
Negate a predicate
68 69 70 |
# File 'lib/dry/schema/predicate.rb', line 68 def ! Negation.new(self) end |
#ensure_valid ⇒ 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.
73 74 75 76 77 |
# File 'lib/dry/schema/predicate.rb', line 73 def ensure_valid if compiler.predicates[name].arity - 1 != args.size raise ArgumentError, "#{name} predicate arity is invalid" end end |
#to_ast ⇒ Array Also known as: ast
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.
Dump predicate to an AST
91 92 93 |
# File 'lib/dry/schema/predicate.rb', line 91 def to_ast(*) [:predicate, [name, compiler.predicates.arg_list(name, *args)]] end |
#to_rule ⇒ 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.
Compile predicate to a rule object
82 83 84 |
# File 'lib/dry/schema/predicate.rb', line 82 def to_rule compiler.visit(to_ast) end |