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

Inherits:
BasicObject
Defined in:
lib/dry/validation/schema/rule.rb

Direct Known Subclasses

Check, Result

Defined Under Namespace

Classes: Check, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#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: &



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

#classObject



32
33
34
# File 'lib/dry/validation/schema/rule.rb', line 32

def class
  Schema::Rule
end

#is_a?(other) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/dry/validation/schema/rule.rb', line 45

def is_a?(other)
  self.class == other
end

#notObject



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



36
37
38
# File 'lib/dry/validation/schema/rule.rb', line 36

def to_ary
  node
end

#to_checkObject



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