Class: Validation::Rule::StretchyRule
- Inherits:
-
Object
- Object
- Validation::Rule::StretchyRule
show all
- Defined in:
- lib/validation/rule/stretchy_rule.rb
Instance Method Summary
collapse
Constructor Details
#initialize(params = {}) ⇒ StretchyRule
Returns a new instance of StretchyRule.
5
6
7
|
# File 'lib/validation/rule/stretchy_rule.rb', line 5
def initialize(params = {})
@params = params
end
|
Instance Method Details
#empty_ok?(value) ⇒ Boolean
17
18
19
|
# File 'lib/validation/rule/stretchy_rule.rb', line 17
def empty_ok?(value)
!required? && is_empty?(value)
end
|
#error_key ⇒ Object
9
10
11
|
# File 'lib/validation/rule/stretchy_rule.rb', line 9
def error_key
raise "Override in subclass"
end
|
#invalid_empty?(value) ⇒ Boolean
21
22
23
|
# File 'lib/validation/rule/stretchy_rule.rb', line 21
def invalid_empty?(value)
required? && is_empty?(value)
end
|
#is_empty?(value) ⇒ Boolean
25
26
27
|
# File 'lib/validation/rule/stretchy_rule.rb', line 25
def is_empty?(value)
value.nil? || (value.respond_to?(:empty?) && value.empty?)
end
|
#params ⇒ Object
33
34
35
|
# File 'lib/validation/rule/stretchy_rule.rb', line 33
def params
@params
end
|
#required? ⇒ Boolean
29
30
31
|
# File 'lib/validation/rule/stretchy_rule.rb', line 29
def required?
!!(params.is_a?(Hash) && params[:required])
end
|
#valid_value?(value) ⇒ Boolean
13
14
15
|
# File 'lib/validation/rule/stretchy_rule.rb', line 13
def valid_value?(value)
raise "Override in subclass"
end
|