class Form::ActiveModel::Validations::Result::ResultErrors
Public Class Methods
new(a, b, success, amv_errors)
click to toggle source
Calls superclass method
# File lib/reform/form/active_model/validations.rb, line 125 def initialize(a, b, success, amv_errors) super(a, b) @success = success @amv_errors = amv_errors end
Public Instance Methods
[](k)
click to toggle source
Calls superclass method
# File lib/reform/form/active_model/validations.rb, line 135 def [](k) super(k.to_sym) || [] end
add(key, error_text, **error_options)
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 144 def add(key, error_text, **error_options) # use rails magic to get the correct error_text and make sure we still update details and fields error = @amv_errors.add(key, error_text, **error_options) error = [error.message] unless error.is_a?(Array) # using error_text instead of text to either keep the symbol which will be # magically replaced with the translate or directly the string - this is also # required otherwise in the custom_errors method we will add the actual message in the # ActiveModel::Errors#details which is not correct if a symbol was passed here Reform::Contract::CustomError.new(key, error_text, @result.to_results) # but since messages method is actually already defined in `Reform::Contract::Result::Errors # we need to update the @dotted_errors instance variable to add or merge a new error @dotted_errors.key?(key) ? @dotted_errors[key] |= error : @dotted_errors[key] = error instance_variable_set(:@dotted_errors, @dotted_errors) end
empty?()
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 131 def empty? @success end
full_messages()
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 170 def full_messages base_errors = @amv_errors.full_messages form_fields = @amv_errors.instance_variable_get(:@base).instance_variable_get(:@fields) nested_errors = full_messages_for_nested_fields(form_fields) [base_errors, nested_errors].flatten.compact end
method_missing(m, *args, &block)
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 161 def method_missing(m, *args, &block) @amv_errors.send(m, *args, &block) # send all methods to the AMV errors, even privates. end
respond_to?(method, include_all = false)
click to toggle source
Calls superclass method
# File lib/reform/form/active_model/validations.rb, line 166 def respond_to?(method, include_all = false) @amv_errors.respond_to?(method, include_all) ? true : super end
to_s()
click to toggle source
rails expects this to return a stringified hash of the messages
# File lib/reform/form/active_model/validations.rb, line 140 def to_s messages.to_s end
Private Instance Methods
full_messages_for_nested_fields(form_fields)
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 180 def full_messages_for_nested_fields(form_fields) form_fields.map { |field| full_messages_for_twin(field[1]) } end
full_messages_for_twin(object)
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 184 def full_messages_for_twin(object) return get_collection_errors(object) if object.is_a? Disposable::Twin::Collection return get_amv_errors(object) if object.is_a? Disposable::Twin nil end
get_amv_errors(object)
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 195 def get_amv_errors(object) object.instance_variable_get(:@amv_errors).full_messages end
get_collection_errors(twin_collection)
click to toggle source
# File lib/reform/form/active_model/validations.rb, line 191 def get_collection_errors(twin_collection) twin_collection.map { |twin| get_amv_errors(twin) } end