Module: ColumnsTrace

Defined in:
lib/columns_trace.rb,
lib/columns_trace/railtie.rb,
lib/columns_trace/version.rb,
lib/columns_trace/registry.rb,
lib/columns_trace/log_reporter.rb,
lib/columns_trace/created_record.rb,
lib/columns_trace/rails_integration.rb,
lib/columns_trace/sidekiq_integration.rb

Defined Under Namespace

Modules: Registry Classes: CreatedRecord, LogReporter, Railtie, SidekiqMiddleware

Constant Summary collapse

VERSION =
"0.3.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backtrace_cleanerObject



82
83
84
# File 'lib/columns_trace.rb', line 82

def backtrace_cleaner
  @backtrace_cleaner
end

.ignored_columnsObject

Configures columns that will be ignored.

Examples:

Global setting

ColumnsTrace.ignored_columns = [:updated_at]

Per-model setting

ColumnsTrace.ignored_columns = [:updated_at, { User => :admin }]


58
59
60
# File 'lib/columns_trace.rb', line 58

def ignored_columns
  @ignored_columns
end

.ignored_modelsObject



32
33
34
# File 'lib/columns_trace.rb', line 32

def ignored_models
  @ignored_models
end

.reporterObject

Allows to set the reporter. Defaults to log reporter that outputs to ‘log/columns_trace.log` file when inside a rails application.



79
80
81
# File 'lib/columns_trace.rb', line 79

def reporter
  @reporter
end

Class Method Details

.configure {|_self| ... } ⇒ Object

A convenient method to configure this gem.

Examples:

ColumnsTrace.configure do |config|
  # ...
end

Yields:

  • (_self)

Yield Parameters:

  • _self (ColumnsTrace)

    the object that the method was called on



110
111
112
# File 'lib/columns_trace.rb', line 110

def configure
  yield self
end

.enable_sidekiq_tracing!Object

Enables integration with Sidekiq, which is disabled by default.



98
99
100
101
# File 'lib/columns_trace.rb', line 98

def enable_sidekiq_tracing!
  require_relative "columns_trace/sidekiq_integration"
  true
end

.ignored_column?(model, column) ⇒ Boolean

Returns:

  • (Boolean)


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

def ignored_column?(model, column)
  ignored_columns.any? do |value|
    if value.is_a?(Hash)
      columns = value[model] || value[model.name] || value[model.name.to_sym]
      if columns
        columns = Array(columns).map(&:to_s)
        columns.include?(column)
      end
    else
      value.to_s == column
    end
  end
end

.ignored_model?(model) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/columns_trace.rb', line 47

def ignored_model?(model)
  ignored_models.include?(model)
end

.report(title) ⇒ Object

Manually trace columns usage in an arbitrary code.

Examples:

task my_rake_task: :environment do
  ColumnsTrace.report("my_rake_task") do
    # do stuff
  end
end

Parameters:

  • title (String)

    title of the reporting, e.g. controller action etc



25
26
27
28
29
# File 'lib/columns_trace.rb', line 25

def report(title)
  Registry.clear
  yield
  reporter.report(title, Registry.created_records)
end