mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
rename context to serialization_context
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
require 'active_support/core_ext/class/attribute'
|
||||
require 'active_model_serializers/serialization_context'
|
||||
|
||||
module ActionController
|
||||
module Serialization
|
||||
@@ -46,7 +47,7 @@ module ActionController
|
||||
|
||||
[:_render_option_json, :_render_with_renderer_json].each do |renderer_method|
|
||||
define_method renderer_method do |resource, options|
|
||||
options.fetch(:context) { options[:context] = request }
|
||||
options.fetch(:serialization_context) { options[:serialization_context] = ActiveModelSerializers::SerializationContext.new(request) }
|
||||
serializable_resource = get_serializer(resource, options)
|
||||
super(serializable_resource, options)
|
||||
end
|
||||
|
||||
@@ -222,7 +222,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def pagination_links_for(serializer, options)
|
||||
JsonApi::PaginationLinks.new(serializer.object, options[:context]).serializable_hash(options)
|
||||
JsonApi::PaginationLinks.new(serializer.object, options[:serialization_context]).serializable_hash(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,11 +41,11 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def url(options)
|
||||
@url ||= options.fetch(:links, {}).fetch(:self, nil) || original_url
|
||||
@url ||= options.fetch(:links, {}).fetch(:self, nil) || request_url
|
||||
end
|
||||
|
||||
def original_url
|
||||
@original_url ||= context.original_url[/\A[^?]+/]
|
||||
def request_url
|
||||
@request_url ||= context.request_url
|
||||
end
|
||||
|
||||
def query_parameters
|
||||
|
||||
10
lib/active_model_serializers/serialization_context.rb
Normal file
10
lib/active_model_serializers/serialization_context.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
module ActiveModelSerializers
|
||||
class SerializationContext
|
||||
attr_reader :request_url, :query_parameters
|
||||
|
||||
def initialize(request)
|
||||
@request_url = request.original_url[/\A[^?]+/]
|
||||
@query_parameters = request.query_parameters
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user