Class: Dry::Validation::Rule

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

Direct Known Subclasses

Each, Key, Set, Value

Defined Under Namespace

Classes: Composite, Conjunction, Disjunction, Each, Key, Set, Value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, predicate) ⇒ Rule

Returns a new instance of Rule.



100
101
102
103
# File 'lib/dry/validation/rule.rb', line 100

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



98
99
100
# File 'lib/dry/validation/rule.rb', line 98

def name
  @name
end

#predicateObject (readonly)

Returns the value of attribute predicate.



98
99
100
# File 'lib/dry/validation/rule.rb', line 98

def predicate
  @predicate
end

Instance Method Details

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



110
111
112
# File 'lib/dry/validation/rule.rb', line 110

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

#curry(*args) ⇒ Object



120
121
122
# File 'lib/dry/validation/rule.rb', line 120

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

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



115
116
117
# File 'lib/dry/validation/rule.rb', line 115

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

#to_aryObject Also known as: to_a



105
106
107
# File 'lib/dry/validation/rule.rb', line 105

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