Class: Caprese::Adapter::JsonApi::ResourceIdentifier
- Inherits:
-
Object
- Object
- Caprese::Adapter::JsonApi::ResourceIdentifier
- Defined in:
- lib/caprese/adapter/json_api/resource_identifier.rb
Class Method Summary collapse
- .for_type_with_id(type, id, options) ⇒ Object
- .type_for(class_name, serializer_type = nil, transform_options = {}) ⇒ Object
Instance Method Summary collapse
Constructor Details
#initialize(serializer, options) ⇒ ResourceIdentifier
28 29 30 31 |
# File 'lib/caprese/adapter/json_api/resource_identifier.rb', line 28 def initialize(serializer, ) @id = id_for(serializer) @type = type_for(serializer, ) end |
Class Method Details
.for_type_with_id(type, id, options) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/caprese/adapter/json_api/resource_identifier.rb', line 19 def self.for_type_with_id(type, id, ) return nil if id.blank? { id: id.to_s, type: type_for(:no_class_needed, type, ) } end |
.type_for(class_name, serializer_type = nil, transform_options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/caprese/adapter/json_api/resource_identifier.rb', line 5 def self.type_for(class_name, serializer_type = nil, = {}) inflection = if ActiveModelSerializers.config.jsonapi_resource_type == :singular :singularize else :pluralize end raw_type = serializer_type || class_name.underscore raw_type = ActiveSupport::Inflector.public_send(inflection, raw_type) JsonApi.send(:transform_key_casing!, raw_type, ) end |
Instance Method Details
#as_json ⇒ Object
33 34 35 |
# File 'lib/caprese/adapter/json_api/resource_identifier.rb', line 33 def as_json { id: id, type: type } end |