Sha256: 2c4c86e825925f22d98935a4f980655bacc817b06ec805481bb369e7f5d4c8fe

Contents?: true

Size: 652 Bytes

Versions: 12

Compression:

Stored size: 652 Bytes

Contents

# frozen_string_literal: true

module JSONAPI
  class Document
    # A jsonapi resource identifier
    class ResourceId

      attr_accessor :type, :id

      # @param type [String | Symbol] The type of the resource identifier
      # @param id [String | Symbol] The id of the resource identifier
      def initialize(type:, id:)
        @type = type.to_s
        @id = id.to_s
      end

      # Represents ResourceId as a JSON parsable string
      def to_s
        "{ \"type\": \"#{@type}\", \"id\": \"#{@id}\" }"
      end

      # Represents ResourceID as a jsonapi hash
      def to_h
        { type: @type, id: @id }
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
easy-jsonapi-1.0.11 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.10 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.9 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.8 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.7 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.6 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.5 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.4 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.3 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.2 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.1 lib/easy/jsonapi/document/resource_id.rb
easy-jsonapi-1.0.0 lib/easy/jsonapi/document/resource_id.rb