Sha256: 16ce1255c1a99ce638c189c60297f9df432385aea815087d5c6b0ed74e71fcea

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

module IIPolicy
  class LogSubscriber < ActiveSupport::LogSubscriber
    def start_call_all(event)
      debug do
        policy = event.payload[:policy]
        action = event.payload[:action]
        "  Calling #{policy.class}##{action} with #{policy.context}"
      end
    end

    def process_call(event)
      debug do
        policy = event.payload[:policy]
        action = event.payload[:action]
        "  Called #{policy.class}##{action} and return #{policy._result} (#{additional_log(event)})"
      end
    end

    private

    def additional_log(event)
      additions = ["Duration: %.1fms" % event.duration]
      additions << "Allocations: %d" % event.allocations if event.respond_to?(:allocations)
      additions.join(', ')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ii_policy-2.3.0 lib/ii_policy/log_subscriber.rb