Class: SqlPatches

Inherits:
Object
  • Object
show all
Defined in:
lib/patches/sql_patches.rb

Class Method Summary collapse

Class Method Details

.class_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/patches/sql_patches.rb', line 11

def self.class_exists?(name)
  eval(name + ".class").to_s.eql?('Class')
rescue NameError
  false
end

.elapsed_time(start_time) ⇒ Object



35
36
37
# File 'lib/patches/sql_patches.rb', line 35

def self.elapsed_time(start_time)
  ((Time.now - start_time).to_f * 1000).round(1)
end

.module_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/patches/sql_patches.rb', line 17

def self.module_exists?(name)
  eval(name + ".class").to_s.eql?('Module')
rescue NameError
  false
end

.patched=(val) ⇒ Object



7
8
9
# File 'lib/patches/sql_patches.rb', line 7

def self.patched=(val)
  @patched = val
end

.patched?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/patches/sql_patches.rb', line 3

def self.patched?
  @patched
end

.record_sql(statement, &block) ⇒ Object



23
24
25
26
27
28
# File 'lib/patches/sql_patches.rb', line 23

def self.record_sql(statement, &block)
  start  = Time.now
  result = yield
  record = ::Rack::MiniProfiler.record_sql( statement, elapsed_time(start) )
  return result, record
end

.should_measure?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/patches/sql_patches.rb', line 30

def self.should_measure?
  current = ::Rack::MiniProfiler.current
  (current && current.measure)
end