Class: Dry::Validation::Rule

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

Direct Known Subclasses

Check, Composite, Each, Group, Key, Negation, Set, Value

Defined Under Namespace

Classes: Check, Composite, Conjunction, Disjunction, Each, ExclusiveDisjunction, Group, Implication, Key, Negation, Result, Set, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, predicate) ⇒ Rule

Returns a new instance of Rule.



26
27
28
29
# File 'lib/dry/validation/rule.rb', line 26

def initialize(name, predicate)
  @name = name
  @predicate = predicate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#predicateObject (readonly)

Returns the value of attribute predicate.



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

def predicate
  @predicate
end

Instance Method Details

#and(other) ⇒ Object Also known as: &



48
49
50
# File 'lib/dry/validation/rule.rb', line 48

def and(other)
  Conjunction.new(self, other)
end

#call(*args) ⇒ Object



39
40
41
# File 'lib/dry/validation/rule.rb', line 39

def call(*args)
  Validation.Result(args, predicate.call, self)
end

#curry(*args) ⇒ Object



76
77
78
# File 'lib/dry/validation/rule.rb', line 76

def curry(*args)
  self.class.new(name, predicate.curry(*args))
end

#negationObject



68
69
70
# File 'lib/dry/validation/rule.rb', line 68

def negation
  Negation.new(self)
end

#new(predicate) ⇒ Object



72
73
74
# File 'lib/dry/validation/rule.rb', line 72

def new(predicate)
  self.class.new(name, predicate)
end

#or(other) ⇒ Object Also known as: |



53
54
55
# File 'lib/dry/validation/rule.rb', line 53

def or(other)
  Disjunction.new(self, other)
end

#predicate_idObject



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

def predicate_id
  predicate.id
end

#then(other) ⇒ Object Also known as: >



63
64
65
# File 'lib/dry/validation/rule.rb', line 63

def then(other)
  Implication.new(self, other)
end

#to_aryObject Also known as: to_a



43
44
45
# File 'lib/dry/validation/rule.rb', line 43

def to_ary
  [type, [name, predicate.to_ary]]
end

#typeObject



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

def type
  :rule
end

#xor(other) ⇒ Object Also known as: ^



58
59
60
# File 'lib/dry/validation/rule.rb', line 58

def xor(other)
  ExclusiveDisjunction.new(self, other)
end