Class: ActiveRecord::SqlAnalyzer::Analyzer
- Inherits:
-
Object
- Object
- ActiveRecord::SqlAnalyzer::Analyzer
- Defined in:
- lib/active_record/sql_analyzer/analyzer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize ⇒ Analyzer
constructor
A new instance of Analyzer.
-
#logger(klass) ⇒ Object
Logger class to use for recording data.
-
#name(name) ⇒ Object
How to tag the data.
- #setup ⇒ Object
-
#tables(names) ⇒ Object
Tables to watch for this analyzer.
Constructor Details
#initialize ⇒ Analyzer
Returns a new instance of Analyzer.
6 7 8 |
# File 'lib/active_record/sql_analyzer/analyzer.rb', line 6 def initialize @options = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/active_record/sql_analyzer/analyzer.rb', line 4 def @options end |
Instance Method Details
#[](key) ⇒ Object
10 11 12 |
# File 'lib/active_record/sql_analyzer/analyzer.rb', line 10 def [](key) @options[key] end |
#logger(klass) ⇒ Object
Logger class to use for recording data
24 25 26 |
# File 'lib/active_record/sql_analyzer/analyzer.rb', line 24 def logger(klass) @options[:logger] = klass end |
#name(name) ⇒ Object
How to tag the data
29 30 31 32 33 34 35 |
# File 'lib/active_record/sql_analyzer/analyzer.rb', line 29 def name(name) if !name.is_a?(String) && name !~ /\A([a-z0-9A-Z_]+)\z/ raise ArgumentError, "Name for this analyzer can only contain [a-z0-9A-Z_] characters" end @options[:name] = name end |
#setup ⇒ Object
37 38 39 40 41 42 |
# File 'lib/active_record/sql_analyzer/analyzer.rb', line 37 def setup @options[:logger_instance] ||= (@options[:logger] || RedactedLogger).new( SqlAnalyzer.config[:logger_root_path], @options[:name] ) end |
#tables(names) ⇒ Object
Tables to watch for this analyzer
15 16 17 18 19 20 21 |
# File 'lib/active_record/sql_analyzer/analyzer.rb', line 15 def tables(names) unless names.is_a?(Array) raise ArgumentError, "Names of tables must be an array" end @options[:table_regex] = /\A\s*((SELECT|DELETE).*(FROM|JOIN)|(INSERT\s+INTO|UPDATE))\s+`?(#{names.join('|')})`?/i end |