class ActiveModelSerializers::Adapter::JsonApi::ResourceIdentifier
def self.for_type_with_id(type, id, options)
def self.for_type_with_id(type, id, options) return nil if id.blank? { id: id.to_s, type: type_for(:no_class_needed, type, options) } end
def self.type_for(class_name, serializer_type = nil, transform_options = {})
def self.type_for(class_name, serializer_type = nil, transform_options = {}) if serializer_type raw_type = serializer_type else inflection = if ActiveModelSerializers.config.jsonapi_resource_type == :singular :singularize else :pluralize end raw_type = class_name.underscore raw_type = ActiveSupport::Inflector.public_send(inflection, raw_type) raw_type .gsub!('/'.freeze, ActiveModelSerializers.config.jsonapi_namespace_separator) raw_type end JsonApi.send(:transform_key_casing!, raw_type, transform_options) end
def as_json
def as_json return nil if id.blank? { id: id, type: type } end
def id_for(serializer)
def id_for(serializer) serializer.read_attribute_for_serialization(:id).to_s end
def initialize(serializer, options)
def initialize(serializer, options) @id = id_for(serializer) @type = type_for(serializer, options) end
def type_for(serializer, transform_options)
def type_for(serializer, transform_options) self.class.type_for(serializer.object.class.name, serializer._type, transform_options) end