Skip to content

Rebased / updated @AKHarris' "custom links defined per resource"#571

Merged
lgebhardt merged 10 commits intoJSONAPI-Resources:masterfrom
reidab:AKHarris-feature/custom-links-defined-per-resource
Feb 16, 2016
Merged

Rebased / updated @AKHarris' "custom links defined per resource"#571
lgebhardt merged 10 commits intoJSONAPI-Resources:masterfrom
reidab:AKHarris-feature/custom-links-defined-per-resource

Conversation

@reidab
Copy link
Copy Markdown
Contributor

@reidab reidab commented Dec 14, 2015

A quick attempt to resurrect @akharris' PR #486 😄

This branch rebases the changes from #486 onto the current master, fixing merge conflicts, and updates the custom_link lambda to receive ResourceSerializer#custom_generation_options, per this comment.

@reidab reidab changed the title Rebased / updated @AKHarris' "feature/custom links defined per resource" Rebased / updated @AKHarris' "custom links defined per resource" Dec 14, 2015
@akharris
Copy link
Copy Markdown
Contributor

👍

@reidab thanks! Sorry I've been MIA.

@reidab
Copy link
Copy Markdown
Contributor Author

reidab commented Dec 15, 2015

Another option here would be to make this more closely mirror the resource meta feature, by removing the custom_link DSL and just providing a custom_links(options) method that people can override to provide a hash that will be merged with the auto-generated links hash.

e.g.

class BookResource < JSONAPI::Resource
  def custom_links(options)
    {
      raw: options[:serialzer].link_builder.self_link(self) + "/raw",
      related: {
        href: options[:serialzer].link_builder.self_link(self) + "/related",
        meta: {
          count: 10
        }
      }
    }
  end
end

@akharris
Copy link
Copy Markdown
Contributor

@reidab I started initially by implementing custom_link as a DSL but I've (fairly lately) become a big fan of using primitive data types by default. I really like Hashes, and the example above seems is clear and elegant to me. It also encourages me to look at the link_builder object to understand #self_link and any other methods that may be useful to me (and encouraging users of a library to look at source code is a plus imo).

And then maybe the DSL should emerge from use cases (perhaps the raw becomes super common and should thus have some shorthand for building it).

These are just a few of my immediate thoughts.

@reidab
Copy link
Copy Markdown
Contributor Author

reidab commented Dec 16, 2015

Okay, I took a stab at simplifying things down to an override of custom_links that mirrors the meta implementation. If we like this approach, I'd also like to put together a PR implementing custom_relationships in the same way.

lcoq referenced this pull request in lcoq/jsonapi-resources Dec 19, 2015
Comment thread test/unit/resource/resource_test.rb Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These resources are not being used in the tests. Could you please remove?

You can run COVERAGE=true bundle exec rake test to make sure you're at 100% coverage.

@akharris
Copy link
Copy Markdown
Contributor

akharris commented Feb 9, 2016

ping @reidab. take it away 👏

@reidab reidab force-pushed the AKHarris-feature/custom-links-defined-per-resource branch from 0642f61 to 9ff1fd5 Compare February 10, 2016 11:48
@reidab
Copy link
Copy Markdown
Contributor Author

reidab commented Feb 10, 2016

👍 Removed unused resources, verified 100% coverage, and rebased onto current master.

lgebhardt added a commit that referenced this pull request Feb 16, 2016
…ined-per-resource

Rebased / updated @akharris' "custom links defined per resource"
@lgebhardt lgebhardt merged commit 4defb2a into JSONAPI-Resources:master Feb 16, 2016
@lgebhardt
Copy link
Copy Markdown
Contributor

Thanks @reidab and @akharris!

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

Successfully merging this pull request may close these issues.

3 participants