class Reform::Contract::Result::Errors
Provides the old API for Rails and friends. Note that this might become an optional “deprecation” gem in Reform
3.
Constants
- DottedErrors
PROTOTYPING. THIS WILL GO TO A SEPARATE GEM IN REFORM 2.4/3.0.
Public Class Methods
new(result, form)
click to toggle source
# File lib/reform/errors.rb, line 4 def initialize(result, form) @result = result # DISCUSS: we don't use this ATM? @form = form @dotted_errors = {} # Reform does not endorse this style of error msgs. DottedErrors.(@form, [], @dotted_errors) end
Public Instance Methods
[](name)
click to toggle source
# File lib/reform/errors.rb, line 36 def [](name) @dotted_errors[name] || [] end
add(key, error_test)
click to toggle source
we need to delegate adding error to result because every time we call form.errors a new instance of this class is created so we need to update the @results array to be able to add custom errors here. This method will actually work only AFTER a validate call has been made
# File lib/reform/errors.rb, line 53 def add(key, error_test) @result.add_error(key, error_test) end
empty?()
click to toggle source
needed for rails form helpers
# File lib/reform/errors.rb, line 45 def empty? messages.empty? end
full_messages()
click to toggle source
# File lib/reform/errors.rb, line 29 def full_messages @dotted_errors.collect { |path, errors| human_field = path.to_s.gsub(/([\.\_])+/, " ").gsub(/(\b\w)+/) { |s| s.capitalize } errors.collect { |message| "#{human_field} #{message}" } }.flatten end
messages(*args)
click to toggle source
# File lib/reform/errors.rb, line 25 def messages(*args) @dotted_errors end
size()
click to toggle source
# File lib/reform/errors.rb, line 40 def size messages.size end