Module: MongoidRailsInstrumentation

Defined in:
lib/mongoid-rails-instrumentation.rb,
lib/mongoid-rails-instrumentation/railtie.rb,
lib/mongoid-rails-instrumentation/version.rb,
lib/mongoid-rails-instrumentation/log_subscriber.rb

Defined Under Namespace

Classes: MopedLogSubscriber, Railtie

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.instrument(klass) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/mongoid-rails-instrumentation.rb', line 5

def self.instrument(klass)
  klass.class_eval do 
    def logging(operations)
      instrument_start = (logger = Moped.logger) && logger.debug? && Time.new
      yield
    ensure
      if instrument_start
        instrument_end   = 1000 * (Time.new.to_f - instrument_start.to_f)
        MopedLogSubscriber.runtime += instrument_end
        MopedLogSubscriber.query_count += 1
        log_operations(logger, operations, instrument_end) 
      end
    end
  end
end