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

Easier presenters #16

Open
ozydingo opened this issue May 18, 2023 · 0 comments
Open

Easier presenters #16

ozydingo opened this issue May 18, 2023 · 0 comments

Comments

@ozydingo
Copy link
Owner

It can be cumbersome to add attributes such as

  FactoryBurgers::Presenters.present("Foo") do
    attributes do |object|
      {
        id: object.id,
        name: object.name,
        description: object.description,
        foo: object.foo,
        bar: object.bar,
        baz: object.baz,
      }
    end
  end

Proposal: support

  FactoryBurgers::Presenters.present("Foo") do
    attribute :id
    attribute :name
    attribute :description
    attribute :foo
    attribute :bar
    attribute :baz
    attribute(:custom_field) { |object| object.something_else }
  end

or even more terse, adding onto the existing attributes method

  FactoryBurgers::Presenters.present("Foo") do
    attributes :id, :name, :description, :foo, :bar, :baz do |object|
      {
        custom_field: object.something_else,
      }
    end

Current workaround

  FactoryBurgers::Presenters.present("Foo") do
    attributes do |object|
      object.attributes.slice("id", "name", "description", "foo", "bar", "baz").merge(
        {custom_field: object.something_else}
      )
    end
  end
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