class Reform::Contract::CustomError
a “fake” Dry schema object to add into the @results array super ugly hack required for 2.3.x version since we are creating a new Reform::Errors instance every time we call form.errors
Attributes
hint[R]
messages[R]
Public Class Methods
new(key, error_text, results)
click to toggle source
# File lib/reform/contract/custom_error.rb, line 7 def initialize(key, error_text, results) @key = key @error_text = error_text @errors = {key => Array(error_text)} @messages = @errors @hint = {} @results = results merge! end
Public Instance Methods
errors(**_args)
click to toggle source
dry 1.x errors method has 1 kwargs argument
# File lib/reform/contract/custom_error.rb, line 29 def errors(**_args) @errors end
failure?()
click to toggle source
# File lib/reform/contract/custom_error.rb, line 24 def failure? true end
merge!()
click to toggle source
# File lib/reform/contract/custom_error.rb, line 33 def merge! # to_h required for dry_v 1.x since the errors are Dry object instead of an hash @results.map(&:errors) .detect { |hash| hash.to_h.key?(@key) } .tap { |hash| hash.nil? ? @results << self : hash.to_h[@key] |= Array(@error_text) } end
success?()
click to toggle source
# File lib/reform/contract/custom_error.rb, line 20 def success? false end