trailblazer/cells

Undefined method `<<' for Hash when using custom rule and errors.yml

Closed this issue · 1 comments

Running the following

require 'dry-validation'

Schema = Dry::Validation.Schema do
  configure { config.messages_file = "config/errors.yml" }
  each do
    schema do
      optional(:name).maybe(:str?)
      optional(:url).maybe(:str?)
      optional(:is_home).maybe(:bool?)

      # needs is_home or name
      rule(be_reasonable: [:is_home, :name]) do |is_home, name|
        is_home.eql?(true) ^ name.filled?
      end
    end
  end
end

validation = Schema.call([{ url: {foo: :bar} }])

validation.messages

will result in an error:

/usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/message_set.rb:51:in `block (2 levels) in to_h': undefined method `<<' for {:url=>["must be a string"]}:Hash (NoMethodError)
    from /usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/message_set.rb:50:in `each'
    from /usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/message_set.rb:50:in `block in to_h'
    from /usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/message_set.rb:47:in `each'
    from /usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/message_set.rb:47:in `reduce'
    from /usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/message_set.rb:47:in `to_h'
    from /usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/message_set.rb:22:in `dump'
    from /usr/local/bundle/gems/dry-validation-0.9.3/lib/dry/validation/result.rb:42:in `messages'
    from bug.rb:21:in `<main>'

config/errors.yml looks like this:

en:
  errors:
    be_reasonable: Please provide name or set is_home!

I am using dry-validation 0.9.3 with ruby 2.2.3.

Can someone help me with this issue? Thanks in advance!

Sry, wrong project!