title: Conditional links with active_model_serializers
body: <p>I'm trying to create a hypermedia api in rails. I'd like to serialize my payloads with active_model_serializers using the json_api adapter. But it doesn't seem trivial to serialize links conditionaly.</p>
  
  <p>It's kind of a blog application where users can follow other users. So when I serialize a User resource, say for UserA, I want to have a link with rel :follow if current_user is not following UserA and a link with rel :unfollow if current_user is already following UserA.
  This seems like an extremely trivial use case when creating a hypermedia api. Does anyone know if there's any good way of doing this with active_model_serializers?</p>
  
  <p>I currently wrote something like this (and include it in all serializers):</p>
  
  <pre><code>def self.link(rel, &amp;block)
        serializer = self
        super do
          user = scope
          next unless serializer.can?(user, rel, @object)
          instance_eval(&amp;block)
        end
      end
  
  # And in serializer (just as usual):
  
  link :self do
    api_user_path(object.id)
  end
  </code></pre>
  
  <p>It does work. But it just don't feel right. And I wouldn't be surprised if future changes to active_model_serializers screw things up for me.</p>