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.



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

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



12
13
14
# File 'lib/active_model_serializers/serialization_context.rb', line 12

def default_url_options
  @default_url_options ||= {}
end

.url_helpersObject



8
9
10
# File 'lib/active_model_serializers/serialization_context.rb', line 8

def url_helpers
  @url_helpers ||= Module.new
end

Instance Attribute Details

#key_transformObject (readonly)

Returns the value of attribute key_transform.



26
27
28
# File 'lib/active_model_serializers/serialization_context.rb', line 26

def key_transform
  @key_transform
end

#query_parametersObject (readonly)

Returns the value of attribute query_parameters.



26
27
28
# File 'lib/active_model_serializers/serialization_context.rb', line 26

def query_parameters
  @query_parameters
end

#request_urlObject (readonly)

Returns the value of attribute request_url.



26
27
28
# File 'lib/active_model_serializers/serialization_context.rb', line 26

def request_url
  @request_url
end