representable
representable copied to clipboard
instance: documentation is wrong
From http://trailblazer.to/gems/representable/3.0/function-api.html#instance:
property :artist,
instance: ->(fragment) do
fragment["type"] == "rockstar" ? Rockstar.new : Artist.new
end
This way, we are not getting what is supposed to be fragment, but instead there's a giant hash including full document, fragment and other parameters. Correct way seems to be either:
property :artist,
instance: ->(fragment: **) do
fragment["type"] == "rockstar" ? Rockstar.new : Artist.new
end
(add represented: and other options if needed), or just use the original hash as options and do something like:
property :artist,
instance: ->(options) do
options[:fragment]["type"] == "rockstar" ? Rockstar.new : Artist.new
end
Ia also looks like class: option description at the same page in it's lambda form may be affected by this too, but I didn't try.