Class: Dry::Validation::Schema::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/schema/rule.rb

Direct Known Subclasses

Check

Defined Under Namespace

Classes: Check

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/dry/validation/schema/rule.rb', line 5

def name
  @name
end

#nodeObject (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

#notObject



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_aryObject Also known as: to_a



18
19
20
# File 'lib/dry/validation/schema/rule.rb', line 18

def to_ary
  node
end

#to_checkObject



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