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

Allow dynamic link names. #187

Open
dblock opened this issue Mar 16, 2016 · 0 comments
Open

Allow dynamic link names. #187

dblock opened this issue Mar 16, 2016 · 0 comments

Comments

@dblock
Copy link
Contributor

dblock commented Mar 16, 2016

A model that has image_versions might want to have a link for image item in the field. Like so:

{
  "id" : 123,
  "image_versions" : ["small", "large"],
  "_links" : {
     "image:small" : {
       "href" : "http://example.org/images/123/small.jpg"
     },
     "image:large" : {
       "href" : "http://example.org/images/123/large.jpg"
     }
   }
}

we can override https://github.com/apotonick/roar/blob/master/lib/roar/hypermedia.rb#L54, but maybe we want a better DSL? How about something that is evaluated on an instance before representing it?

before_represent do
  represented.image_versions each do |image_version|
    link image_version do 
       "http://example.com/images/#{represented.id}/#{image_version}.jpg"
    end
  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