Class: Hyphy::SQLStatement
- Inherits:
-
Object
- Object
- Hyphy::SQLStatement
- Defined in:
- lib/hyphy/sql_statement.rb
Constant Summary collapse
- DIGIT_MARKER =
'<digit>'
Instance Attribute Summary collapse
-
#benchmark_runs ⇒ Object
Returns the value of attribute benchmark_runs.
-
#benchmark_time ⇒ Object
Returns the value of attribute benchmark_time.
-
#binds ⇒ Object
Returns the value of attribute binds.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#orm_adapter ⇒ Object
Returns the value of attribute orm_adapter.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#statement ⇒ Object
Returns the value of attribute statement.
-
#trace ⇒ Object
Returns the value of attribute trace.
Instance Method Summary collapse
- #application_trace ⇒ Object
- #digitless ⇒ Object
- #duration ⇒ Object
-
#initialize(opts = {}) ⇒ SQLStatement
constructor
A new instance of SQLStatement.
- #insert? ⇒ Boolean
- #select? ⇒ Boolean
- #stripped_statement ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ SQLStatement
Returns a new instance of SQLStatement.
15 16 17 18 19 20 21 22 23 |
# File 'lib/hyphy/sql_statement.rb', line 15 def initialize(opts={}) @statement = opts[:statement] @start_time = opts[:start_time] @end_time = opts[:end_time] @orm_adapter = opts[:orm_adapter] @trace = opts[:trace] || [] @binds = opts[:binds] || [] = opts[:metadata] || {} end |
Instance Attribute Details
#benchmark_runs ⇒ Object
Returns the value of attribute benchmark_runs.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def benchmark_runs @benchmark_runs end |
#benchmark_time ⇒ Object
Returns the value of attribute benchmark_time.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def benchmark_time @benchmark_time end |
#binds ⇒ Object
Returns the value of attribute binds.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def binds @binds end |
#end_time ⇒ Object
Returns the value of attribute end_time.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def end_time @end_time end |
#metadata ⇒ Object
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def end |
#orm_adapter ⇒ Object
Returns the value of attribute orm_adapter.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def orm_adapter @orm_adapter end |
#start_time ⇒ Object
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def start_time @start_time end |
#statement ⇒ Object
Returns the value of attribute statement.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def statement @statement end |
#trace ⇒ Object
Returns the value of attribute trace.
5 6 7 |
# File 'lib/hyphy/sql_statement.rb', line 5 def trace @trace end |
Instance Method Details
#application_trace ⇒ Object
45 46 47 48 49 50 |
# File 'lib/hyphy/sql_statement.rb', line 45 def application_trace return @application_trace if @application_trace regex = Regexp.new("^#{Dir.pwd}") @application_trace ||= trace.select { |line| regex.match(line) } end |
#digitless ⇒ Object
41 42 43 |
# File 'lib/hyphy/sql_statement.rb', line 41 def digitless @digitless ||= stripped_statement.gsub(/\d+/, DIGIT_MARKER) end |
#duration ⇒ Object
25 26 27 |
# File 'lib/hyphy/sql_statement.rb', line 25 def duration @duration ||= (end_time - start_time) end |
#insert? ⇒ Boolean
37 38 39 |
# File 'lib/hyphy/sql_statement.rb', line 37 def insert? @insert ||= stripped_statement.upcase.match(/^INSERT/) end |
#select? ⇒ Boolean
33 34 35 |
# File 'lib/hyphy/sql_statement.rb', line 33 def select? @select ||= stripped_statement.upcase.match(/^SELECT/) end |
#stripped_statement ⇒ Object
29 30 31 |
# File 'lib/hyphy/sql_statement.rb', line 29 def stripped_statement @stripped_statement ||= statement.strip end |