Sha256: 6ceb732375c443d6e1da2996641e31b5af624b143967937ec18013b44e4ab857

Contents?: true

Size: 885 Bytes

Versions: 1

Compression:

Stored size: 885 Bytes

Contents

module ActiveModel
  class Serializer
    module Adapter
      class JsonApi
        class Link
          def initialize(serializer, value)
            @object = serializer.object
            @scope = serializer.scope

            # Use the return value of the block unless it is nil.
            if value.respond_to?(:call)
              @value = instance_eval(&value)
            else
              @value = value
            end
          end

          def href(value)
            @href = value
            nil
          end

          def meta(value)
            @meta = value
            nil
          end

          def as_json
            return @value if @value

            hash = { href: @href }
            hash.merge!(meta: @meta) if @meta

            hash
          end

          protected

          attr_reader :object, :scope
        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/adapter/json_api/link.rb