Sha256: ec88db2d0ea4519f15de970defb63fe0a71048031b8a18066dfced596b5fc13c

Contents?: true

Size: 783 Bytes

Versions: 1

Compression:

Stored size: 783 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_model_serializers-0.10.0.rc4 lib/active_model/serializer/links.rb