Class: Dryv::Rule
- Inherits:
-
Object
show all
- Defined in:
- lib/dryv/rule.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(value, errors = Dryv::Errors.new, **args) ⇒ Rule
Returns a new instance of Rule.
6
7
8
9
10
|
# File 'lib/dryv/rule.rb', line 6
def initialize(value, errors = Dryv::Errors.new, **args)
@value = value
@errors = errors
@args = args.symbolize_keys
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
4
5
6
|
# File 'lib/dryv/rule.rb', line 4
def args
@args
end
|
#errors ⇒ Object
Returns the value of attribute errors.
4
5
6
|
# File 'lib/dryv/rule.rb', line 4
def errors
@errors
end
|
#value ⇒ Object
Returns the value of attribute value.
4
5
6
|
# File 'lib/dryv/rule.rb', line 4
def value
@value
end
|
Instance Method Details
#+(right) ⇒ Object
46
47
48
|
# File 'lib/dryv/rule.rb', line 46
def +(right)
Dryv::Rules::Collection.new(self, errors, args.merge(right: right))
end
|
#add_error ⇒ Object
18
19
20
|
# File 'lib/dryv/rule.rb', line 18
def add_error
errors.add(key, messages[name.to_s] || 'invalid')
end
|
#and(right) ⇒ Object
Also known as:
&
28
29
30
|
# File 'lib/dryv/rule.rb', line 28
def and(right)
Dryv::Rules::And.new(self, errors, args.merge(right: right))
end
|
#clone ⇒ Object
23
24
25
|
# File 'lib/dryv/rule.rb', line 23
def clone
self.class.new(value, errors.clone, args)
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/dryv/rule.rb', line 13
def name
args[:name]
end
|
#or(right) ⇒ Object
Also known as:
|
40
41
42
|
# File 'lib/dryv/rule.rb', line 40
def or(right)
Dryv::Rules::Or.new(self, errors, args.merge(right: right))
end
|
#then(right) ⇒ Object
Also known as:
>
34
35
36
|
# File 'lib/dryv/rule.rb', line 34
def then(right)
Dryv::Rules::Then.new(self, errors, args.merge(right: right))
end
|
#valid? ⇒ Boolean
51
52
53
|
# File 'lib/dryv/rule.rb', line 51
def valid?
raise NotImplementedError
end
|