Class: ScoutApm::Utils::ActiveRecordMetricName

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/utils/active_record_metric_name.rb

Constant Summary collapse

DEFAULT_METRIC =
"SQL/Unknown"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sql, name) ⇒ ActiveRecordMetricName

Returns a new instance of ActiveRecordMetricName.



8
9
10
11
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 8

def initialize(sql, name)
  @sql = sql
  @name = name.to_s
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 6

def name
  @name
end

#sqlObject (readonly)

Returns the value of attribute sql.



6
7
8
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 6

def sql
  @sql
end

Instance Method Details

#eql?(o) ⇒ Boolean

For the layer lookup. Reminder: #eql? is for Hash equality: returns true if obj and other refer to the same hash key.

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 38

def eql?(o)
  self.class    == o.class &&
  name.downcase == o.name.downcase
end

#hashObject

For the layer lookup.



31
32
33
34
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 31

def hash
  h = name.downcase.hash
  h
end

#to_sObject

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



19
20
21
22
23
24
25
26
27
28
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 19

def to_s
  return DEFAULT_METRIC unless name
  return DEFAULT_METRIC unless model && operation

  if parsed = parse_operation
    "#{model}/#{parsed}"
  else
    "SQL/other"
  end
end