module WebFetch::Validatable
Provides boilerplate for a validatable model
Attributes
errors[R]
Public Instance Methods
valid?()
click to toggle source
# File lib/web_fetch/concerns/validatable.rb, line 8 def valid? @errors = [] validate @errors.empty? end
Private Instance Methods
error(name, aux = '')
click to toggle source
# File lib/web_fetch/concerns/validatable.rb, line 26 def error(name, aux = '') aux = ' ' + aux unless aux.empty? @errors.push(I18n.t(name) + aux) end
validate()
click to toggle source
# File lib/web_fetch/concerns/validatable.rb, line 16 def validate error = <<-MSG.gsub(/\s+/, ' ') Override and call `error(:i18n_key)` as many times as required for each validation failure. Supplementary text can be added to the error by passing as the second parameter to `error` MSG raise NotImplementedError, error end