Module: RailsCallbackLog

Defined in:
lib/rails-callback_log.rb,
lib/rails_callback_log/version.rb

Defined Under Namespace

Modules: CallTemplateExtension, CallbackExtension

Constant Summary collapse

FILTER =

Filtering is very expensive. It makes my test suite more than 50% slower. So, it’s off by default.

ENV["RAILS_CALLBACK_LOG_FILTER"].present?.freeze

Class Method Summary collapse

Class Method Details

.gem_versionObject



4
5
6
# File 'lib/rails_callback_log/version.rb', line 4

def self.gem_version
  ::Gem::Version.new('0.3.0')
end

.log(msg) ⇒ Object



20
21
22
23
24
# File 'lib/rails-callback_log.rb', line 20

def log(msg)
  if !FILTER || caller.any? { |line| matches_filter?(line) }
    logger.debug(format("Callback: %s", msg))
  end
end

.loggerObject



12
13
14
# File 'lib/rails-callback_log.rb', line 12

def logger
  ::Rails.logger || ::Logger.new(STDOUT)
end

.matches_filter?(str) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rails-callback_log.rb', line 16

def matches_filter?(str)
  source_location_filters.any? { |f| str.start_with?(f) }
end