Module: ActiveRecordCallbacksDebug

Defined in:
lib/active_record_callbacks_debug.rb,
lib/active_record_callbacks_debug/version.rb,
lib/active_record_callbacks_debug/configuration.rb

Defined Under Namespace

Modules: CallTemplateExtension Classes: Configuration

Constant Summary collapse

VERSION =
'0.0.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



7
8
9
# File 'lib/active_record_callbacks_debug.rb', line 7

def configuration
  @configuration
end

Class Method Details

.bench_format(bench) ⇒ Object



42
43
44
45
46
# File 'lib/active_record_callbacks_debug.rb', line 42

def bench_format(bench)
  return "#{format('%.6f', bench.total)} seg | " if bench.present?

  ''
end

.configure {|configuration| ... } ⇒ Object

Yields:



56
57
58
# File 'lib/active_record_callbacks_debug.rb', line 56

def configure
  yield(configuration)
end

.define_type(params) ⇒ Object



32
33
34
35
36
# File 'lib/active_record_callbacks_debug.rb', line 32

def define_type(params)
  return :proc if params[:over_block].present?
  return :val if params[:over_method] == 'validate'
  return :meth if params[:over_method].present?
end

.klass(klass_source) ⇒ Object



38
39
40
# File 'lib/active_record_callbacks_debug.rb', line 38

def klass(klass_source)
  klass_source.class.to_s
end

.log(params, bench = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record_callbacks_debug.rb', line 13

def log(params, bench=nil)
  type = define_type params
  klass = klass params[:target]
  msg = "#{type.upcase}: #{klass} => "

  case type
  when :proc
    msg += "#{params[:over_method]} => proc: #{params[:over_block]}"
  when :val
    msg += "#{params[:over_target].class} > attr: #{params[:over_target].attributes}"
  when :meth
    msg += params[:over_method].to_s
  end

  msg = "#{bench_format(bench)}#{msg}"
  logger.debug msg
  msg
end

.loggerObject



9
10
11
# File 'lib/active_record_callbacks_debug.rb', line 9

def logger
  configuration.logger || Logger.new
end

.resetObject



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

def reset
  @configuration = ActiveRecordCallbacksDebug::Configuration.new
end