Module: ActiveModelSerializers::Logging::Macros

Defined in:
lib/active_model_serializers/logging.rb

Overview

Macros that can be used to customize the logging of class or instance methods, by extending the class or its singleton.

Adapted from:

https://github.com/rubygems/rubygems/blob/cb28f5e991/lib/rubygems/deprecate.rb

Provides a single method notify to be used to declare when something a method notifies, with the argument callback_name of the notification callback.

class Adapter
  def self.klass_method
    # ...
  end

  def instance_method
    # ...
  end

  include ActiveModelSerializers::Logging::Macros
  notify :instance_method, :render

  class << self
    extend ActiveModelSerializers::Logging::Macros
    notify :klass_method, :render
  end
end

Instance Method Summary collapse

Instance Method Details

#notify(name, callback_name) ⇒ Object

Simple notify method that wraps up name in a dummy method. It notifies on with the callback_name notifier on each call to the dummy method, telling what the current serializer and adapter are being rendered. Adapted from:

https://github.com/rubygems/rubygems/blob/cb28f5e991/lib/rubygems/deprecate.rb

63
64
65
66
67
68
69
70
71
72
73
# File 'lib/active_model_serializers/logging.rb', line 63

def notify(name, callback_name)
  class_eval do
    old = "_notifying_#{callback_name}_#{name}"
    alias_method old, name
    define_method name do |*args, &block|
      run_callbacks callback_name do
        send old, *args, &block
      end
    end
  end
end