Sha256: f8e9a7e8bedaa58d3c9a0d59d878159b553a3f660eb5ef2bebba39ef365d1cda

Contents?: true

Size: 863 Bytes

Versions: 21

Compression:

Stored size: 863 Bytes

Contents

module Graphiti
  # If the object we are serializing has the instance variable
  # +@_jsonapi_temp_id+, render +temp-id+ in the {http://jsonapi.org/format/#document-resource-identifier-objects resource identifier}
  #
  # Why? Well, when the request is a nested POST, creating the main entity as
  # well as relationships, we need some way of telling the client, "hey, the
  # object you have in memory, that you just sent to the server, has been
  # persisted and now has id X".
  #
  # +@_jsonapi_temp_id+ is set within this library. You should never have to
  # reference it directly.
  module SerializableTempId
    # Common interface for jsonapi-rb extensions
    def as_jsonapi(*)
      super.tap do |hash|
        if (temp_id = @object.instance_variable_get(:@_jsonapi_temp_id))
          hash[:'temp-id'] = temp_id
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
graphiti-1.7.6 lib/graphiti/extensions/temp_id.rb
graphiti-1.7.5 lib/graphiti/extensions/temp_id.rb
graphiti-1.7.4 lib/graphiti/extensions/temp_id.rb
graphiti-1.7.3 lib/graphiti/extensions/temp_id.rb
graphiti-1.7.2 lib/graphiti/extensions/temp_id.rb
graphiti-1.7.1 lib/graphiti/extensions/temp_id.rb
graphiti-1.7.0 lib/graphiti/extensions/temp_id.rb
graphiti-1.6.4 lib/graphiti/extensions/temp_id.rb
graphiti-1.6.3 lib/graphiti/extensions/temp_id.rb
graphiti-1.6.2 lib/graphiti/extensions/temp_id.rb
graphiti-1.6.1 lib/graphiti/extensions/temp_id.rb
graphiti-1.6.0 lib/graphiti/extensions/temp_id.rb
graphiti-1.5.3 lib/graphiti/extensions/temp_id.rb
graphiti-1.5.2 lib/graphiti/extensions/temp_id.rb
graphiti-1.5.1 lib/graphiti/extensions/temp_id.rb
graphiti-1.5.0 lib/graphiti/extensions/temp_id.rb
graphiti-1.4.0 lib/graphiti/extensions/temp_id.rb
graphiti-1.3.9 lib/graphiti/extensions/temp_id.rb
graphiti-1.3.8 lib/graphiti/extensions/temp_id.rb
graphiti-1.3.7 lib/graphiti/extensions/temp_id.rb