Class: Reform::Contract::Result::Errors
- Inherits:
-
Object
- Object
- Reform::Contract::Result::Errors
- Defined in:
- lib/reform/errors.rb
Overview
Provides the old API for Rails and friends. Note that this might become an optional “deprecation” gem in Reform 3.
Constant Summary collapse
- DottedErrors =
PROTOTYPING. THIS WILL GO TO A SEPARATE GEM IN REFORM 2.4/3.0.
->(form, prefix, hash) do result = form.to_result result..collect { |k, v| hash[[*prefix, k].join(".").to_sym] = v } form.schema.each(twin: true) do |dfn| Disposable::Twin::PropertyProcessor.new(dfn, form).() do |frm, i| form_obj = i ? form.send(dfn[:name])[i] : form.send(dfn[:name]) DottedErrors.(form_obj, [*prefix, dfn[:name]], hash) end end end
Instance Method Summary collapse
- #[](name) ⇒ Object
-
#add(key, error_test) ⇒ Object
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.
-
#empty? ⇒ Boolean
needed for rails form helpers.
- #full_messages ⇒ Object
-
#initialize(result, form) ⇒ Errors
constructor
A new instance of Errors.
- #messages(*args) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(result, form) ⇒ Errors
Returns a new instance of Errors.
4 5 6 7 8 9 10 |
# 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 |
Instance Method Details
#[](name) ⇒ Object
36 37 38 |
# File 'lib/reform/errors.rb', line 36 def [](name) @dotted_errors[name] || [] end |
#add(key, error_test) ⇒ Object
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
53 54 55 |
# File 'lib/reform/errors.rb', line 53 def add(key, error_test) @result.add_error(key, error_test) end |
#empty? ⇒ Boolean
needed for rails form helpers
45 46 47 |
# File 'lib/reform/errors.rb', line 45 def empty? .empty? end |
#full_messages ⇒ Object
29 30 31 32 33 34 |
# File 'lib/reform/errors.rb', line 29 def @dotted_errors.collect { |path, errors| human_field = path.to_s.gsub(/([\.\_])+/, " ").gsub(/(\b\w)+/) { |s| s.capitalize } errors.collect { || "#{human_field} #{}" } }.flatten end |
#messages(*args) ⇒ Object
25 26 27 |
# File 'lib/reform/errors.rb', line 25 def (*args) @dotted_errors end |
#size ⇒ Object
40 41 42 |
# File 'lib/reform/errors.rb', line 40 def size .size end |