Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options hash passed to setter has incorrect value for collection properties #231

Open
conradchan opened this issue Jun 19, 2019 · 0 comments

Comments

@conradchan
Copy link

Problem

options[:fragment] seems to correspond to the wrong property when referenced inside a setter block for a collection property.

Manufactured example:

class DemoRepresenter < Representable::Decorator
  include Representable::Hash

  property :foo
  collection :bars, setter: ->(options) do
    p "Input in setter for bars is value #{options[:input]}"
    p "Fragment in setter for bars is value #{options[:fragment]}"
  end
end

DemoRepresenter.new(OpenStruct.new).from_hash(
  {"foo"=>"fooValue", "bars"=>["barValue1", "barValue2"]}
).to_h

Actual:

The above code prints the following:

"Input in setter for bars is value [\"barValue1\", \"barValue2\"]"
"Fragment in setter for bars is value fooValue"

Expected:

The expected behavior would be for the fragment to correspond to ["barValue1", "barValue2"] since it's in the scope of the bars property.

Version:

3.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant