Module: Pg_explain

Defined in:
lib/pg_explain.rb

Overview

This module contains:

  • Activation/disactivation methods

  • Configuration methods

  • Output formatting methods

Constant Summary collapse

@@color =
false
@@analyze =
false
@@enable =
false

Class Method Summary collapse

Class Method Details

.configure(options = {}) ⇒ Object

To setup the configuration options



29
30
31
32
# File 'lib/pg_explain.rb', line 29

def self.configure(options = {})
  @@color   ||= options[:color]
  @@analyze ||= options[:analyze]
end

.disableObject

Disables the plugin



19
20
21
# File 'lib/pg_explain.rb', line 19

def self.disable
  @@enable = false
end

.enableObject

Activates the plugin



14
15
16
# File 'lib/pg_explain.rb', line 14

def self.enable
  @@enable = true
end

.enabled?Boolean

Check if the plugin is enabled

Returns:

  • (Boolean)


24
25
26
# File 'lib/pg_explain.rb', line 24

def self.enabled?
  @@enable
end

.format(message) ⇒ Object

Formats the results of the explain query



40
41
42
43
# File 'lib/pg_explain.rb', line 40

def self.format(message)
  formatted_message = "\n" + message.collect { |line| "  " + colorize(line["QUERY PLAN"]) }.join("\n") + "\n"
  color ? "\033[01;30m#{formatted_message}\033[00m" : formatted_message
end

.methodObject

Returns “Explain” or “Explain Analyze”



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

def self.method
  ("Explain Analyze" if analyze) || "Explain"
end