Class: Bureaucrat::Validators::BaseValidator
- Inherits:
-
Object
- Object
- Bureaucrat::Validators::BaseValidator
show all
- Defined in:
- lib/bureaucrat/validators.rb
Instance Method Summary
collapse
Constructor Details
#initialize(limit_value) ⇒ BaseValidator
Returns a new instance of BaseValidator.
68
69
70
|
# File 'lib/bureaucrat/validators.rb', line 68
def initialize(limit_value)
@limit_value = limit_value
end
|
Instance Method Details
#call(value) ⇒ Object
88
89
90
91
92
93
94
95
96
|
# File 'lib/bureaucrat/validators.rb', line 88
def call(value)
cleaned = clean(value)
params = { limit_value: @limit_value, show_value: cleaned }
if compare(cleaned, @limit_value)
msg = Utils.format_string(message, params)
raise ValidationError.new(msg, code, params)
end
end
|
#clean(x) ⇒ Object
84
85
86
|
# File 'lib/bureaucrat/validators.rb', line 84
def clean(x)
x
end
|
#code ⇒ Object
76
77
78
|
# File 'lib/bureaucrat/validators.rb', line 76
def code
:limit_value
end
|
#compare(a, b) ⇒ Object
80
81
82
|
# File 'lib/bureaucrat/validators.rb', line 80
def compare(a, b)
a.object_id != b.object_id
end
|
#message ⇒ Object
72
73
74
|
# File 'lib/bureaucrat/validators.rb', line 72
def message
'Ensure this value is %(limit_value)s (it is %(show_value)s).'
end
|