module ActiveModelSerializers

{jsonapi.org/format/ JSON API specification} rubocop:disable Style/AsciiComments TODO: implement!

☐ https://github.com/rails-api/active_model_serializers/issues/1235

TODO: use uri_template in link generation?

☐ https://github.com/rails-api/active_model_serializers/pull/1282#discussion_r42528812
  see gem https://github.com/hannesg/uri_template
  spec http://tools.ietf.org/html/rfc6570
  impl https://developer.github.com/v3/#schema https://api.github.com/

TODO: validate against a JSON schema document?

☐ https://github.com/rails-api/active_model_serializers/issues/1162
☑ https://github.com/rails-api/active_model_serializers/pull/1270

TODO: Routing

☐ https://github.com/rails-api/active_model_serializers/pull/1476

TODO: Query Params

☑ `include` https://github.com/rails-api/active_model_serializers/pull/1131
☑ `fields` https://github.com/rails-api/active_model_serializers/pull/700
☑ `page[number]=3&page[size]=1` https://github.com/rails-api/active_model_serializers/pull/1041
☐ `filter`
☐ `sort`

Provides a single method deprecate to be used to declare when something is going away.

class Legacy
  def self.klass_method
    # ...
  end

  def instance_method
    # ...
  end

  extend ActiveModelSerializers::Deprecate
  deprecate :instance_method, "ActiveModelSerializers::NewPlace#new_method"

  class << self
    extend ActiveModelSerializers::Deprecate
    deprecate :klass_method, :none
  end
end

Adapted from github.com/rubygems/rubygems/blob/1591331/lib/rubygems/deprecate.rb

ActiveModelSerializers::Logging

https://github.com/rails/rails/blob/280654ef88/activejob/lib/active_job/logging.rb

Based on discussion in github.com/rails/rails/pull/23712#issuecomment-184977238, the JSON API media type will have its own format/renderer.

> We recommend the media type be registered on its own as jsonapi when a jsonapi Renderer and deserializer (Http::Parameters::DEFAULT_PARSERS) are added.

Usage:

ActiveSupport.on_load(:action_controller) do

require 'active_model_serializers/register_jsonapi_renderer'

end

And then in controllers, use `render jsonapi: model` rather than `render json: model, adapter: :json_api`.

For example, in a controller action, we can: respond_to do |format|

format.jsonapi { render jsonapi: model }

end

or

render jsonapi: model

No wrapper format needed as it does not apply (i.e. no `wrap_parameters format: [jsonapi]`)

Attributes

logger[RW]

Public Class Methods

config() click to toggle source
# File lib/active_model_serializers.rb, line 27
def self.config
  ActiveModel::Serializer.config
end
default_include_directive() click to toggle source

Memoized default include directive @return [JSONAPI::IncludeDirective]

# File lib/active_model_serializers.rb, line 42
def self.default_include_directive
  @default_include_directive ||= JSONAPI::IncludeDirective.new(config.default_includes, allow_wildcard: true)
end
eager_load!() click to toggle source
Calls superclass method
# File lib/active_model_serializers.rb, line 54
def self.eager_load!
  super
  ActiveModel::Serializer.eager_load!
end
location_of_caller() click to toggle source

The file name and line number of the caller of the caller of this method.

# File lib/active_model_serializers.rb, line 32
def self.location_of_caller
  caller[1] =~ /(.*?):(\d+).*?$/i
  file = Regexp.last_match(1)
  lineno = Regexp.last_match(2).to_i

  [file, lineno]
end
silence_warnings() { || ... } click to toggle source
# File lib/active_model_serializers.rb, line 46
def self.silence_warnings
  original_verbose = $VERBOSE
  $VERBOSE = nil
  yield
ensure
  $VERBOSE = original_verbose
end