Sha256: 5eddede301523fe069c05c31aff8757c513095c851cce814f37e4a4f64a02ab7

Contents?: true

Size: 873 Bytes

Versions: 10

Compression:

Stored size: 873 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) { resource_url(object) }
        # @example
        #   link(:self) { "http://example.com/resource/#{object.id}" }
        # @example
        #   link :resource, "http://example.com/resource"
        #
        def link(name, value = nil, &block)
          _links[name] = block || value
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
active_model_serializers-0.10.5 lib/active_model/serializer/concerns/links.rb
active_model_serializers-0.10.4 lib/active_model/serializer/concerns/links.rb
agi_active_model_serializers-0.10.9 lib/active_model/serializer/concerns/links.rb
agi_active_model_serializers-0.10.8 lib/active_model/serializer/concerns/links.rb
agi_active_model_serializers-0.10.7 lib/active_model/serializer/concerns/links.rb
active_model_serializers-0.10.3 lib/active_model/serializer/concerns/links.rb
active_model_serializers-0.10.2 lib/active_model/serializer/links.rb
active_model_serializers-0.10.1 lib/active_model/serializer/links.rb
active_model_serializers-0.10.0 lib/active_model/serializer/links.rb
active_model_serializers-0.10.0.rc5 lib/active_model/serializer/links.rb