Class: Dry::Validation::Schema::Rule
- Inherits:
- BasicObject
- Defined in:
- lib/dry/validation/schema/rule.rb
Defined Under Namespace
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: #&)
- #class ⇒ Object
-
#initialize(name, node) ⇒ Rule
constructor
A new instance of Rule.
- #is_a?(other) ⇒ Boolean
- #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.
27 28 29 30 |
# File 'lib/dry/validation/schema/rule.rb', line 27 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: &
53 54 55 |
# File 'lib/dry/validation/schema/rule.rb', line 53 def and(other) self.class.new(:"#{name}_and_#{other.name}", [:and, [node, other.to_ary]]) end |
#class ⇒ Object
32 33 34 |
# File 'lib/dry/validation/schema/rule.rb', line 32 def class Schema::Rule end |
#is_a?(other) ⇒ Boolean
45 46 47 |
# File 'lib/dry/validation/schema/rule.rb', line 45 def is_a?(other) self.class == other end |
#not ⇒ Object
49 50 51 |
# File 'lib/dry/validation/schema/rule.rb', line 49 def not self.class.new(:"not_#{name}", [:not, node]) end |
#or(other) ⇒ Object Also known as: |
58 59 60 |
# File 'lib/dry/validation/schema/rule.rb', line 58 def or(other) self.class.new(:"#{name}_or_#{other.name}", [:or, [node, other.to_ary]]) end |
#then(other) ⇒ Object Also known as: >
68 69 70 |
# File 'lib/dry/validation/schema/rule.rb', line 68 def then(other) self.class.new(:"#{name}_then_#{other.name}", [:implication, [node, other.to_ary]]) end |
#to_ary ⇒ Object Also known as: to_a
36 37 38 |
# File 'lib/dry/validation/schema/rule.rb', line 36 def to_ary node end |
#to_check ⇒ Object
41 42 43 |
# File 'lib/dry/validation/schema/rule.rb', line 41 def to_check Rule::Check.new(name, [:check, [name, [:predicate, [name, []]]]]) end |
#xor(other) ⇒ Object Also known as: ^
63 64 65 |
# File 'lib/dry/validation/schema/rule.rb', line 63 def xor(other) self.class.new(:"#{name}_xor_#{other.name}", [:xor, [node, other.to_ary]]) end |