module ErrorProne::Model
Mixed in to objects you wish to validate.
@example
class FakeModel < Struct.new(:name) include ErrorProne::Model end model = FakeModel.new model.valid? # true model.add_error(:name, :too_cool) model.valid? # false model.errors_for(:name) # [:too_cool]
Public Instance Methods
add_error(field, error)
click to toggle source
@param [Symbol] field Identifies which field to add an error to @param [Symbol] error Identifies the type of error that occured @return [self] The model itself
# File lib/error_prone.rb, line 34 def add_error(field, error) errors.add(field, error) self end
errors()
click to toggle source
@return [ErrorProne::Errors]
# File lib/error_prone.rb, line 27 def errors @errors ||= Errors.new end
errors_for(field)
click to toggle source
@param [Symbol] field The field to find errors for @return [Array] the errors for the given field
# File lib/error_prone.rb, line 22 def errors_for(field) errors.for(field) end
valid?()
click to toggle source
@return [Boolean] false if errors had been added. True if no errors.
# File lib/error_prone.rb, line 40 def valid? errors.empty? end