Class: Dry::Validation::Rule

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

Direct Known Subclasses

Composite, Each, Group, Key, Set, Value

Defined Under Namespace

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, predicate) ⇒ Rule

Returns a new instance of Rule.



8
9
10
11
# File 'lib/dry/validation/rule.rb', line 8

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



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

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

#curry(*args) ⇒ Object



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

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

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



23
24
25
# File 'lib/dry/validation/rule.rb', line 23

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

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



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

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

#to_aryObject Also known as: to_a



13
14
15
# File 'lib/dry/validation/rule.rb', line 13

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