Class: Dry::Validation::Schema::Rule
- Inherits:
-
Object
- Object
- Dry::Validation::Schema::Rule
- Defined in:
- lib/dry/validation/schema/rule.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Check
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #and(other) ⇒ Object (also: #&)
-
#initialize(name, node) ⇒ Rule
constructor
A new instance of Rule.
- #not ⇒ Object
- #or(other) ⇒ Object (also: #|)
- #then(other) ⇒ Object (also: #>)
- #to_ary ⇒ Object (also: #to_a)
- #to_check ⇒ Object
- #xor(other) ⇒ Object (also: #^)
Constructor Details
#initialize(name, node) ⇒ Rule
Returns a new instance of Rule.
13 14 15 16 |
# File 'lib/dry/validation/schema/rule.rb', line 13 def initialize(name, node) @name = name @node = node end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dry/validation/schema/rule.rb', line 5 def name @name end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
5 6 7 |
# File 'lib/dry/validation/schema/rule.rb', line 5 def node @node end |
Instance Method Details
#and(other) ⇒ Object Also known as: &
31 32 33 |
# File 'lib/dry/validation/schema/rule.rb', line 31 def and(other) self.class.new(:"#{name}_and_#{other.name}", [:and, [node, other.to_ary]]) end |
#not ⇒ Object
27 28 29 |
# File 'lib/dry/validation/schema/rule.rb', line 27 def not self.class.new(:"not_#{name}", [:not, node]) end |
#or(other) ⇒ Object Also known as: |
36 37 38 |
# File 'lib/dry/validation/schema/rule.rb', line 36 def or(other) self.class.new(:"#{name}_or_#{other.name}", [:or, [node, other.to_ary]]) end |
#then(other) ⇒ Object Also known as: >
46 47 48 |
# File 'lib/dry/validation/schema/rule.rb', line 46 def then(other) self.class.new(:"#{name}_then_#{other.name}", [:implication, [node, other.to_ary]]) end |
#to_ary ⇒ Object Also known as: to_a
18 19 20 |
# File 'lib/dry/validation/schema/rule.rb', line 18 def to_ary node end |
#to_check ⇒ Object
23 24 25 |
# File 'lib/dry/validation/schema/rule.rb', line 23 def to_check Rule::Check.new(name, [:check, [name, [:predicate, [name, []]]]]) end |
#xor(other) ⇒ Object Also known as: ^
41 42 43 |
# File 'lib/dry/validation/schema/rule.rb', line 41 def xor(other) self.class.new(:"#{name}_xor_#{other.name}", [:xor, [node, other.to_ary]]) end |