Module: Marginalia::ActiveRecordInstrumentation
- Defined in:
- lib/marginalia.rb
Class Method Summary collapse
Instance Method Summary collapse
- #annotate_sql(sql) ⇒ Object
- #exec_query_with_marginalia(sql, name = 'SQL', binds = []) ⇒ Object
- #execute_with_marginalia(sql, name = nil) ⇒ Object
Class Method Details
.included(instrumented_class) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/marginalia.rb', line 8 def self.included(instrumented_class) Marginalia::Comment.components = [:application, :controller, :action] instrumented_class.class_eval do if method_defined? :execute alias_method :execute_without_marginalia, :execute alias_method :execute, :execute_with_marginalia end if method_defined? :exec_query alias_method :exec_query_without_marginalia, :exec_query alias_method :exec_query, :exec_query_with_marginalia end end end |
Instance Method Details
#annotate_sql(sql) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/marginalia.rb', line 23 def annotate_sql(sql) comment = Marginalia::Comment.construct_comment if comment.present? && !sql.match(comment) "#{sql} /*#{comment}*/" else sql end end |
#exec_query_with_marginalia(sql, name = 'SQL', binds = []) ⇒ Object
36 37 38 |
# File 'lib/marginalia.rb', line 36 def exec_query_with_marginalia(sql, name = 'SQL', binds = []) exec_query_without_marginalia(annotate_sql(sql), name, binds) end |
#execute_with_marginalia(sql, name = nil) ⇒ Object
32 33 34 |
# File 'lib/marginalia.rb', line 32 def execute_with_marginalia(sql, name = nil) execute_without_marginalia(annotate_sql(sql), name) end |