Sha256: cad59a42fff7013e5799b98c5c0bdd5f30f762c6fe413d541da4b9c7847d1ac5

Contents?: true

Size: 777 Bytes

Versions: 9

Compression:

Stored size: 777 Bytes

Contents

module JSONAPI
  MEDIA_TYPE = 'application/vnd.api+json'

  module MimeTypes
    def self.install
      Mime::Type.register JSONAPI::MEDIA_TYPE, :api_json

      # :nocov:
      if Rails::VERSION::MAJOR >= 5
        parsers = ActionDispatch::Request.parameter_parsers.merge(
          Mime::Type.lookup(JSONAPI::MEDIA_TYPE).symbol => parser
        )
        ActionDispatch::Request.parameter_parsers = parsers
      else
        ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime::Type.lookup(JSONAPI::MEDIA_TYPE)] = parser
      end
      # :nocov:
    end

    def self.parser
      lambda do |body|
        data = JSON.parse(body)
        data = {:_json => data} unless data.is_a?(Hash)
        data.with_indifferent_access
      end
    end
  end

  MimeTypes.install
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jsonapi-resources-0.8.3 lib/jsonapi/mime_types.rb
jsonapi-resources-0.8.2 lib/jsonapi/mime_types.rb
jsonapi-resources-0.9.0.beta1 lib/jsonapi/mime_types.rb
jsonapi-resources-0.8.1 lib/jsonapi/mime_types.rb
jsonapi-resources-0.8.0 lib/jsonapi/mime_types.rb
jsonapi-resources-0.8.0.beta3 lib/jsonapi/mime_types.rb
jsonapi-resources-0.8.0.beta2 lib/jsonapi/mime_types.rb
jsonapi-resources-0.8.0.beta1 lib/jsonapi/mime_types.rb
jsonapi-resources-0.7.1.beta2 lib/jsonapi/mime_types.rb