Class: ScoutApm::Utils::ActiveRecordMetricName
- Inherits:
-
Object
- Object
- ScoutApm::Utils::ActiveRecordMetricName
- Defined in:
- lib/scout_apm/utils/active_record_metric_name.rb
Constant Summary collapse
- DEFAULT_METRIC =
'SQL/other'.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sql ⇒ Object
readonly
Returns the value of attribute sql.
Instance Method Summary collapse
-
#eql?(o) ⇒ Boolean
(also: #==)
For the layer lookup.
-
#hash ⇒ Object
For the layer lookup.
-
#initialize(sql, name) ⇒ ActiveRecordMetricName
constructor
A new instance of ActiveRecordMetricName.
- #model ⇒ Object
- #normalized_operation ⇒ Object
-
#to_s ⇒ Object
Converts an SQL string and the name (typically assigned automatically by rails) into a Scout metric_name.
Constructor Details
#initialize(sql, name) ⇒ ActiveRecordMetricName
Returns a new instance of ActiveRecordMetricName.
7 8 9 10 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 7 def initialize(sql, name) @sql = sql || "" @name = name.to_s end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 4 def name @name end |
#sql ⇒ Object (readonly)
Returns the value of attribute sql.
4 5 6 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 4 def sql @sql end |
Instance Method Details
#eql?(o) ⇒ Boolean Also known as: ==
For the layer lookup. Reminder: #eql? is for Hash equality: returns true if obj and other refer to the same hash key.
43 44 45 46 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 43 def eql?(o) self.class == o.class && name.downcase == o.name.downcase end |
#hash ⇒ Object
For the layer lookup.
36 37 38 39 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 36 def hash h = name.downcase.hash h end |
#model ⇒ Object
27 28 29 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 27 def model parts.first end |
#normalized_operation ⇒ Object
31 32 33 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 31 def normalized_operation parse_operation end |
#to_s ⇒ Object
Converts an SQL string and the name (typically assigned automatically by rails) into a Scout metric_name.
sql: SELECT “places”.* FROM “places” ORDER BY “places”.“position” ASC name: Place Load metric_name: Place/find
18 19 20 21 22 23 24 25 |
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 18 def to_s parsed = parse_operation if parsed "#{model}/#{parsed}" else regex_name(sql) end end |