Module: SqlMonitor

Defined in:
lib/sql_monitor.rb,
lib/sql_monitor/config.rb,
lib/sql_monitor/engine.rb,
lib/sql_monitor/handler.rb,
lib/sql_monitor/railtie.rb,
lib/sql_monitor/version.rb,
app/controllers/sql_monitor/explain_sql_controller.rb,
app/controllers/sql_monitor/tracking_sqls_controller.rb

Defined Under Namespace

Classes: Config, Engine, Error, ExplainSqlController, Handler, Railtie, TrackingSqlsController

Constant Summary collapse

VERSION =
"0.1.0".freeze

Class Method Summary collapse

Class Method Details

.handlerObject



36
37
38
# File 'lib/sql_monitor.rb', line 36

def self.handler
  @handler
end

.initialize!Object



10
11
12
13
14
# File 'lib/sql_monitor.rb', line 10

def self.initialize!
  # puts "1. initialize sql_monitor"
  raise 'sql monitor initialized twice' if @already_initialized
  @already_initialized = true
end

.setup!Object



16
17
18
19
20
21
22
23
24
# File 'lib/sql_monitor.rb', line 16

def self.setup!
  # puts "2. setup sql_monitor"
  config = SqlMonitor::Config.apply_defaults
  return unless config.enabled

  @handler = SqlMonitor::Handler.new(config)
  @handler.subscribe
  at_exit { @handler.save } if config.save_at_exit
end

.trackObject



26
27
28
29
30
31
32
33
34
# File 'lib/sql_monitor.rb', line 26

def self.track
  config = SqlMonitor::Config.apply_defaults.new
  config.enabled = true
  handler = SqlMonitor::Handler.new(config)
  handler.subscribe
  yield
  handler.unsubscribe
  handler.data
end