Module: ActionController::Serialization

Extended by:
ActiveSupport::Concern
Includes:
Renderers
Defined in:
lib/action_controller/serialization.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#get_serializer(resource, options = {}) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/action_controller/serialization.rb', line 33

def get_serializer(resource, options = {})
  unless use_adapter?
    warn 'ActionController::Serialization#use_adapter? has been removed. '\
      "Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
    options[:adapter] = false
  end

  options.fetch(:namespace) { options[:namespace] = namespace_for_serializer }

  serializable_resource = ActiveModelSerializers::SerializableResource.new(resource, options)
  serializable_resource.serialization_scope ||= options.fetch(:scope) { serialization_scope }
  serializable_resource.serialization_scope_name = options.fetch(:scope_name) { _serialization_scope }
  # For compatibility with the JSON renderer: `json.to_json(options) if json.is_a?(String)`.
  # Otherwise, since `serializable_resource` is not a string, the renderer would call
  # `to_json` on a String and given odd results, such as `"".to_json #=> '""'`
  serializable_resource.adapter.is_a?(String) ? serializable_resource.adapter : serializable_resource
end

#namespace_for_serializerObject


23
24
25
# File 'lib/action_controller/serialization.rb', line 23

def namespace_for_serializer
  @namespace_for_serializer ||= self.class.parent unless self.class.parent == Object
end

#serialization_scopeObject


27
28
29
30
31
# File 'lib/action_controller/serialization.rb', line 27

def serialization_scope
  return unless _serialization_scope && respond_to?(_serialization_scope, true)

  send(_serialization_scope)
end

#use_adapter?Boolean

Deprecated

Returns:

  • (Boolean)

52
53
54
# File 'lib/action_controller/serialization.rb', line 52

def use_adapter?
  true
end