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/other'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (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

#sqlObject (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.

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 48

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

#hashObject

For the layer lookup.



41
42
43
44
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 41

def hash
  h = name.downcase.hash
  h
end

#modelObject

This only returns a value if a name is provided via initialize.



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

def model
  parts.first
end

#normalized_operationObject

This only returns a value if a name is provided via initialize.



36
37
38
# File 'lib/scout_apm/utils/active_record_metric_name.rb', line 36

def normalized_operation
  parse_operation
end

#to_sObject

Converts an SQL string and the name (typically assigned automatically by rails) into a Scout metric_name.

This prefers to use the ActiveRecord-provided name over parsing SQL as parsing is slower.

sql: SELECT “places”.* FROM “places” ORDER BY “places”.“position” ASC name: Place Load metric_name: Place/find



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

def to_s
  return @to_s if @to_s
  parsed = parse_operation
  if parsed
    @to_s = "#{model}/#{parsed}"
  else
    @to_s = regex_name(sql)
  end
end