Module: RailsInstrument

Defined in:
lib/rails_instrument.rb,
lib/rails_instrument/version.rb

Defined Under Namespace

Classes: Engine, Middleware

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.dataObject

:nodoc:



15
16
17
# File 'lib/rails_instrument.rb', line 15

def data #:nodoc:
  $rails_instrument
end

.increment_sql_countObject

:nodoc:



33
34
35
# File 'lib/rails_instrument.rb', line 33

def increment_sql_count #:nodoc:
  data[:sql_count] += 1
end

.initObject

:nodoc:



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

def init #:nodoc:
  $rails_instrument ||= {}
  $rails_instrument[:sql_count] ||= 0
end

.instrument(&block) ⇒ Object

Taken a block and return the instrument object for the operation done on the block. TODO: Make it to work with nested instrument blocks



26
27
28
29
30
31
# File 'lib/rails_instrument.rb', line 26

def instrument(&block)
  raise "A block is not passed" unless block_given?
  RailsInstrument.reset!
  yield
  self
end

.reset!Object

Resets the instrument statistics and counts



6
7
8
# File 'lib/rails_instrument.rb', line 6

def reset!
  $rails_instrument = { :sql_count => 0 }
end

.sql_countObject

Return the number of sql fired from the last reset



20
21
22
# File 'lib/rails_instrument.rb', line 20

def sql_count
  data[:sql_count]
end