active_model_serializers/lib/active_model/serializer/links.rb
Lucas Hosseini 2e87c8effe Fix comment.
2016-01-13 05:41:32 +01:00

34 lines
783 B
Ruby

module ActiveModel
class Serializer
module Links
extend ActiveSupport::Concern
included do
with_options instance_writer: false, instance_reader: true do |serializer|
serializer.class_attribute :_links # @api private
self._links ||= {}
end
extend ActiveSupport::Autoload
end
module ClassMethods
def inherited(base)
super
base._links = _links.dup
end
# Define a link on a serializer.
# @example
# link :self { "//example.com/posts/#{object.id}" }
# @example
# link :self, "//example.com/user"
#
def link(name, value = nil, &block)
_links[name] = block || value
end
end
end
end
end