Class: ActiveModelSerializers::SerializationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model_serializers/serialization_context.rb

Defined Under Namespace

Modules: UrlHelpers

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SerializationContext

Returns a new instance of SerializationContext.



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_model_serializers/serialization_context.rb', line 26

def initialize(*args)
  options = args.extract_options!
  if args.size == 1
    request = args.pop
    options[:request_url] = request.original_url[/\A[^?]+/]
    options[:query_parameters] = request.query_parameters
  end
  @request_url = options.delete(:request_url)
  @query_parameters = options.delete(:query_parameters)
  @url_helpers = options.delete(:url_helpers) || self.class.url_helpers
  @default_url_options = options.delete(:default_url_options) || self.class.default_url_options
end

Class Attribute Details

.default_url_optionsObject



10
11
12
# File 'lib/active_model_serializers/serialization_context.rb', line 10

def default_url_options
  @default_url_options ||= {}
end

.url_helpersObject



6
7
8
# File 'lib/active_model_serializers/serialization_context.rb', line 6

def url_helpers
  @url_helpers ||= Module.new
end

Instance Attribute Details

#key_transformObject (readonly)

Returns the value of attribute key_transform.



24
25
26
# File 'lib/active_model_serializers/serialization_context.rb', line 24

def key_transform
  @key_transform
end

#query_parametersObject (readonly)

Returns the value of attribute query_parameters.



24
25
26
# File 'lib/active_model_serializers/serialization_context.rb', line 24

def query_parameters
  @query_parameters
end

#request_urlObject (readonly)

Returns the value of attribute request_url.



24
25
26
# File 'lib/active_model_serializers/serialization_context.rb', line 24

def request_url
  @request_url
end