Sha256: 162a4bf7825675960848d4888e08232b4b93e4d6ec5e7a08d27f432faa87a747
Contents?: true
Size: 1.12 KB
Versions: 9
Compression:
Stored size: 1.12 KB
Contents
module Shamu module JsonApi module BuilderMethods module Identifier # Write a resource linkage info. # # @param [String] type of the resource. # @param [Object] id of the resource. # @return [self] def identifier( type, id = :not_set ) output[:type] = @type = json_type( type ) output[:id] = if id == :not_set type.id if type.respond_to?( :id ) else id.to_s end self end # (see BaseBuilder#compile) def compile require_identifier! super end private attr_reader :type def json_type( type ) type = type.json_type if type.respond_to?( :json_type ) type = type.model_name.element if type.respond_to?( :model_name ) type = type.name.demodulize.underscore if type.is_a?( Module ) type.to_s end def require_identifier! fail IncompleteResourceError unless type end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems