module FunWithJsonApi
Makes working with JSON:API fun!
Constants
- MEDIA_TYPE
- VERSION
Attributes
configuration[W]
Public Instance Methods
configuration()
click to toggle source
# File lib/fun_with_json_api.rb, line 20 def configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/fun_with_json_api.rb, line 24 def configure yield(configuration) end
deserialize(document, deserializer_class, resource = nil, options = {})
click to toggle source
# File lib/fun_with_json_api.rb, line 28 def deserialize(document, deserializer_class, resource = nil, options = {}) # Prepare the deserializer and the expected config deserializer = deserializer_class.create(options) # Run through initial document structure validation and deserialization unfiltered = FunWithJsonApi::PreDeserializer.parse(document, deserializer) # Check the document matches up with expected resource parameters FunWithJsonApi::SchemaValidator.check(document, deserializer, resource) # Ensure document matches schema, and sanitize values deserializer.sanitize_params(unfiltered) end
deserialize_resource(document, deserializer_class, resource, options = {})
click to toggle source
# File lib/fun_with_json_api.rb, line 42 def deserialize_resource(document, deserializer_class, resource, options = {}) raise ArgumentError, 'resource cannot be nil' if resource.nil? deserialize(document, deserializer_class, resource, options) end
find_collection(document, deserializer_class, options = {})
click to toggle source
# File lib/fun_with_json_api.rb, line 60 def find_collection(document, deserializer_class, options = {}) # Prepare the deserializer for loading a resource deserializer = deserializer_class.create(options.merge(attributes: [], relationships: [])) # Load the collection from the document FunWithJsonApi::FindCollectionFromDocument.find(document, deserializer) end
find_resource(document, deserializer_class, options = {})
click to toggle source
# File lib/fun_with_json_api.rb, line 52 def find_resource(document, deserializer_class, options = {}) # Prepare the deserializer for loading a resource deserializer = deserializer_class.create(options.merge(attributes: [], relationships: [])) # Load the resource from the document id FunWithJsonApi::FindResourceFromDocument.find(document, deserializer) end
sanitize_document(document)
click to toggle source
# File lib/fun_with_json_api.rb, line 47 def sanitize_document(document) document = document.dup.permit!.to_h if document.is_a?(ActionController::Parameters) document.deep_stringify_keys end