Module: ActiveModelSerializers::Callbacks::ClassMethods

Defined in:
lib/active_model_serializers/callbacks.rb

Overview

These methods will be included into any ActiveModelSerializers object, adding callbacks for render.

Instance Method Summary collapse

Instance Method Details

#around_render(*filters, &blk) ⇒ Object

Defines a callback that will get called around the render method, whether it is as_json, to_json, or serializable_hash

class ActiveModelSerializers::SerializableResource
  include ActiveModelSerializers::Callbacks

  around_render do |args, block|
    tag_logger do
      notify_render do
        block.call(args)
      end
    end
  end

  def as_json
    run_callbacks :render do
      adapter.as_json
    end
  end
  # Note: So that we can re-use the instrumenter for as_json, to_json, and
  # serializable_hash, we aren't using the usual format, which would be:
  # def render(args)
  #   adapter.as_json
  # end
end


52
53
54
# File 'lib/active_model_serializers/callbacks.rb', line 52

def around_render(*filters, &blk)
  set_callback(:render, :around, *filters, &blk)
end