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

instance: documentation is wrong #218

Open
infoman opened this issue Apr 4, 2017 · 0 comments
Open

instance: documentation is wrong #218

infoman opened this issue Apr 4, 2017 · 0 comments

Comments

@infoman
Copy link

infoman commented Apr 4, 2017

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.

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