Class: MVCLI::Validatable::Rule
- Inherits:
-
Object
- Object
- MVCLI::Validatable::Rule
- Defined in:
- lib/mvcli/validatable.rb
Instance Method Summary collapse
- #call(validatable, violations, errors) ⇒ Object
-
#initialize(field, message, options, predicate) ⇒ Rule
constructor
A new instance of Rule.
- #read(validatable) ⇒ Object
Constructor Details
#initialize(field, message, options, predicate) ⇒ Rule
Returns a new instance of Rule.
168 169 170 |
# File 'lib/mvcli/validatable.rb', line 168 def initialize(field, , , predicate) @field, , , @predicate = field, , , predicate end |
Instance Method Details
#call(validatable, violations, errors) ⇒ Object
171 172 173 174 175 176 177 178 179 |
# File 'lib/mvcli/validatable.rb', line 171 def call(validatable, violations, errors) value, error = read validatable if error errors[@field] << error else return if value.nil? && ![:nil] violations[@field] << unless @predicate.call value end end |
#read(validatable) ⇒ Object
181 182 183 184 185 |
# File 'lib/mvcli/validatable.rb', line 181 def read(validatable) return validatable.send(@field), nil rescue StandardError => e return nil, e end |