Sha256: c90a61ceabb28dda836818abc44b60741083de2b91b516b8d6928afc4676d173

Contents?: true

Size: 961 Bytes

Versions: 20

Compression:

Stored size: 961 Bytes

Contents

class Remnant
  class Database
    module ClassMethods
      def disable!
        @enabled = false
      end

      def enable!
        @enabled = true
      end

      def enabled?
        @enabled
      end

      def unsuppress!
        @suppress = false
      end

      def suppress?
        @suppress || true
      end

      def record(sql, backtrace = [], &block)
        return block.call unless Remnant::Database.enabled?

        start_time = Time.now
        result = block.call
        queries << Remnant::Database::Query.new(sql, Time.now - start_time, backtrace)

        return result
      end

      def reset
        @suppress = true
        @total_time = nil
        Thread.current['remnant.database.queries'] = []
      end

      def queries
        Thread.current['remnant.database.queries'] ||= []
      end

      def total_time
        @total_time ||= queries.map(&:time).sum * 1000
      end
    end
    extend ClassMethods
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
remnant-1.0.0 lib/remnant/database.rb
remnant-0.4.10 lib/remnant/database.rb
remnant-0.4.9 lib/remnant/database.rb
remnant-0.4.8 lib/remnant/database.rb
remnant-0.4.7 lib/remnant/database.rb
remnant-0.4.6 lib/remnant/database.rb
remnant-0.4.5 lib/remnant/database.rb
remnant-0.9.5 lib/remnant/database.rb
remnant-0.9.4 lib/remnant/database.rb
remnant-0.4.4 lib/remnant/database.rb
remnant-0.9.3 lib/remnant/database.rb
remnant-0.9.2 lib/remnant/database.rb
remnant-0.9.1 lib/remnant/database.rb
remnant-0.9.0 lib/remnant/database.rb
remnant-0.4.3 lib/remnant/database.rb
remnant-0.4.2 lib/remnant/database.rb
remnant-0.4.1 lib/remnant/database.rb
remnant-0.4.0 lib/remnant/database.rb
remnant-0.3.3 lib/remnant/database.rb
remnant-0.3.2 lib/remnant/database.rb