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

Include/Exclude filter options for links #117

Open
dorellang opened this issue Dec 24, 2014 · 1 comment
Open

Include/Exclude filter options for links #117

dorellang opened this issue Dec 24, 2014 · 1 comment

Comments

@dorellang
Copy link

I think it would be nice to skip or include links in the same way you can do it now with plain old properties; maybe something along the lines of
model.to_json include_links: :self
or even
model.to_json include: :self

Currently I have to resort to hackery like this in the representer

      class << self
        alias_method :_ye_olde_link, :link
        def link(rel, *args, &block)
          _ye_olde_link rel, *args do |opts|
            props = opts[:links_exclude] || opts[:links_include]
            if props
              ignore = props.include? rel
              ignore = opts[:links_include]? !ignore : ignore
            else
              ignore = false
            end
            ignore ? nil : instance_exec(opts, &block)
          end
        end
      end

And then call
model.to_json include: :links, include_links: [:self]
Not nice at all... It gets the job done though

@apotonick
Copy link
Member

That's a cool idea! This should be pretty "straight-forward" by extending this: https://github.com/apotonick/roar/blob/master/lib/roar/hypermedia.rb#L59

The options hash is where you could specify the links to be in-/excluded.

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

2 participants