Merge pull request #1322 from bf4/maurogeorge-patch-10

Instrumenting rendering of resources
This commit is contained in:
Benjamin Fleischer
2015-11-19 13:01:38 -06:00
15 changed files with 340 additions and 9 deletions

View File

@@ -2,6 +2,12 @@ require 'set'
module ActiveModel
class SerializableResource
ADAPTER_OPTION_KEYS = Set.new([:include, :fields, :adapter, :meta, :meta_key, :links])
include ActiveModelSerializers::Logging
delegate :serializable_hash, :as_json, :to_json, to: :adapter
notify :serializable_hash, :render
notify :as_json, :render
notify :to_json, :render
# Primary interface to composing a resource with a serializer and adapter.
# @return the serializable_resource, ready for #as_json/#to_json/#serializable_hash.
@@ -11,8 +17,6 @@ module ActiveModel
options.partition { |k, _| ADAPTER_OPTION_KEYS.include? k }.map { |h| Hash[h] }
end
delegate :serializable_hash, :as_json, :to_json, to: :adapter
def serialization_scope=(scope)
serializer_opts[:scope] = scope
end

View File

@@ -1,9 +1,10 @@
require 'rails/railtie'
module ActiveModel
class Railtie < Rails::Railtie
initializer 'active_model_serializers.logger' do
ActiveSupport.on_load(:action_controller) do
ActiveModelSerializers.logger = ActionController::Base.logger
ActiveSupport.on_load(:active_model_serializers) do
self.logger = ActionController::Base.logger
end
end