solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Coerce proc and strict mode don't match #371

Closed herwinw closed 1 year ago

herwinw commented 7 years ago

Probably closely related to #293, but not exactly the same:

class Baz
  include Virtus.model(strict: true)
  attribute :foo, String, coercer: ->(val) { val.to_s }
  attribute :bar, String, required: false
end

p Baz.new(foo: 'a', bar: 'b')
p Baz.new(foo: 'a')
p Baz.new(bar: 'b')

This results in the following error:

virtus/attribute.rb:125:in `value_coerced?': undefined method `success?' for #<Proc:0x915f8fc@/opt/qnet-core/virtus.rb:8 (lambda)> (NoMethodError)