Class: SqlSafetyNet::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_safety_net/configuration.rb

Overview

Configuration for SqlSafetyNet. The various limit attributes are used for adapters that can do query analysis. Queries will be flagged if their query plan exceeds a limit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sql_safety_net/configuration.rb', line 7

def initialize
  @debug = false
  @header = false
  @table_scan_limit = 100
  @temporary_table_limit = 100
  @filesort_limit = 100
  @return_rows_limit = 100
  @examine_rows_limit = 5000
  @query_limit = 10
  @always_show = false
  @position = "top:5px; right: 5px;"
  @time_limit = 300
end

Instance Attribute Details

#examine_rows_limitObject

Returns the value of attribute examine_rows_limit.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def examine_rows_limit
  @examine_rows_limit
end

#filesort_limitObject

Returns the value of attribute filesort_limit.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def filesort_limit
  @filesort_limit
end

#positionObject

Returns the value of attribute position.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def position
  @position
end

#query_limitObject

Returns the value of attribute query_limit.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def query_limit
  @query_limit
end

#return_rows_limitObject

Returns the value of attribute return_rows_limit.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def return_rows_limit
  @return_rows_limit
end

#table_scan_limitObject

Returns the value of attribute table_scan_limit.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def table_scan_limit
  @table_scan_limit
end

#temporary_table_limitObject

Returns the value of attribute temporary_table_limit.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def temporary_table_limit
  @temporary_table_limit
end

#time_limitObject

Returns the value of attribute time_limit.



5
6
7
# File 'lib/sql_safety_net/configuration.rb', line 5

def time_limit
  @time_limit
end

Instance Method Details

#always_show=(val) ⇒ Object

Set a flag to always show information about queries on rendered HTML pages. If this is not set to true, the debug information will only be shown if the queries on the page exceed one of the limits.



49
50
51
# File 'lib/sql_safety_net/configuration.rb', line 49

def always_show=(val)
  @always_show = !!val
end

#always_show?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/sql_safety_net/configuration.rb', line 53

def always_show?
  @always_show
end

#debug=(val) ⇒ Object



31
32
33
# File 'lib/sql_safety_net/configuration.rb', line 31

def debug=(val)
  @debug = !!val
end

#debug?Boolean

Returns:

  • (Boolean)


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

def debug?
  @debug
end

#enable_on(connection_class) ⇒ Object

Enable SqlSafetyNet on a connection. Unless this method is called, the code will not be mixed into the database adapter. This should normally be called only in the development environment.



23
24
25
26
27
28
29
# File 'lib/sql_safety_net/configuration.rb', line 23

def enable_on(connection_class)
  connection_class = connection_class.constantize unless connection_class.is_a?(Class)
  connection_class_name = connection_class.name.split('::').last
  include_class = ConnectionAdapter.const_get(connection_class_name) if ConnectionAdapter.const_defined?(connection_class_name)
  connection_class.send(:include, ConnectionAdapter) unless connection_class.include?(ConnectionAdapter)
  connection_class.send(:include, include_class) if include_class && !connection_class.include?(include_class)
end

#header=(val) ⇒ Object



39
40
41
# File 'lib/sql_safety_net/configuration.rb', line 39

def header=(val)
  @header = !!val
end

#header?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/sql_safety_net/configuration.rb', line 43

def header?
  @header
end