Revert "rename context to serialization_context and add url helpers"

This commit is contained in:
L. Preston Sego III 2015-10-29 08:16:47 -04:00
parent a063cbea21
commit 17be650538
7 changed files with 7 additions and 35 deletions

View File

@ -1,5 +1,4 @@
require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/class/attribute'
require 'action_controller/serialization/context'
module ActionController module ActionController
module Serialization module Serialization
@ -47,7 +46,7 @@ module ActionController
[:_render_option_json, :_render_with_renderer_json].each do |renderer_method| [:_render_option_json, :_render_with_renderer_json].each do |renderer_method|
define_method renderer_method do |resource, options| define_method renderer_method do |resource, options|
options.fetch(:serialization_context) { options[:serialization_context] = Context.new(request) } options.fetch(:context) { options[:context] = request }
serializable_resource = get_serializer(resource, options) serializable_resource = get_serializer(resource, options)
super(serializable_resource, options) super(serializable_resource, options)
end end

View File

@ -1,13 +0,0 @@
module ActionController
module Serialization
class Context
attr_reader :request_url, :query_parameters, :url_helpers
def initialize(request)
@request_url = request.original_url[/\A[^?]+/]
@query_parameters = request.query_parameters
@url_helpers = ActiveModelSerializers.url_helpers
end
end
end
end

View File

@ -206,7 +206,7 @@ module ActiveModel
end end
def links_for(serializer, options) def links_for(serializer, options)
JsonApi::PaginationLinks.new(serializer.object, options[:serialization_context]).serializable_hash(options) JsonApi::PaginationLinks.new(serializer.object, options[:context]).serializable_hash(options)
end end
end end
end end

View File

@ -41,11 +41,11 @@ module ActiveModel
end end
def url(options) def url(options)
@url ||= options.fetch(:links, {}).fetch(:self, nil) || request_url @url ||= options.fetch(:links, {}).fetch(:self, nil) || original_url
end end
def request_url def original_url
@request_url ||= context.request_url @original_url ||= context.original_url[/\A[^?]+/]
end end
def query_parameters def query_parameters

View File

@ -7,18 +7,6 @@ module ActiveModel
end end
end end
initializer 'active_model_serializers.url_helpers' do
ActiveSupport.on_load(:action_controller) do
ActiveModelSerializers.url_helpers = Module.new do
include Rails.application.routes.url_helpers
def self.default_url_options
ActionController::Base.default_url_options
end
end
end
end
initializer 'generators' do |app| initializer 'generators' do |app|
app.load_generators app.load_generators
require 'generators/serializer/resource_override' require 'generators/serializer/resource_override'

View File

@ -7,8 +7,6 @@ module ActiveModelSerializers
mattr_accessor :logger mattr_accessor :logger
self.logger = Rails.logger || Logger.new(IO::NULL) self.logger = Rails.logger || Logger.new(IO::NULL)
mattr_accessor :url_helpers
extend ActiveSupport::Autoload extend ActiveSupport::Autoload
autoload :Model autoload :Model

View File

@ -22,10 +22,10 @@ module ActiveModel
def mock_request(query_parameters = {}, original_url = URI) def mock_request(query_parameters = {}, original_url = URI)
context = Minitest::Mock.new context = Minitest::Mock.new
context.expect(:request_url, original_url) context.expect(:original_url, original_url)
context.expect(:query_parameters, query_parameters) context.expect(:query_parameters, query_parameters)
@options = {} @options = {}
@options[:serialization_context] = context @options[:context] = context
end end
def load_adapter(paginated_collection, options = {}) def load_adapter(paginated_collection, options = {})