Class: GitlabInternalEventsCli::Metric::Identifier

Inherits:
Struct
  • Object
show all
Defined in:
lib/gitlab_internal_events_cli/metric.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



385
386
387
# File 'lib/gitlab_internal_events_cli/metric.rb', line 385

def value
  @value
end

Instance Method Details

#default?Boolean

Refers to the top-level identifiers not included in additional_properties

Returns:

  • (Boolean)


425
426
427
# File 'lib/gitlab_internal_events_cli/metric.rb', line 425

def default?
  %w[user project namespace].include?(value)
end

#descriptionObject

returns a description of the identifier with appropriate grammar to interpolate a description of events



388
389
390
391
392
393
394
395
396
397
398
# File 'lib/gitlab_internal_events_cli/metric.rb', line 388

def description
  if value.nil?
    '%s occurrences'
  elsif value == 'user'
    'users who triggered %s'
  elsif %w[project namespace].include?(value)
    "#{plural} where %s occurred"
  else
    "#{plural} from %s occurrences"
  end
end

#key_path(operator) ⇒ Object

returns a slug which can be used in the metric’s key_path and filepath



407
408
409
410
411
412
413
414
415
416
# File 'lib/gitlab_internal_events_cli/metric.rb', line 407

def key_path(operator)
  case operator.value
  when 'unique_count'
    "distinct_#{reference.tr('.', '_')}_from"
  when 'count'
    'total'
  when 'sum'
    "#{reference.tr('.', '_')}_from"
  end
end

#pluralObject

handles generic pluralization for unknown indentifers



401
402
403
# File 'lib/gitlab_internal_events_cli/metric.rb', line 401

def plural
  default? ? "#{value}s" : "values for '#{value}'"
end

#referenceObject

Returns the identifier string that will be included in the yml



419
420
421
# File 'lib/gitlab_internal_events_cli/metric.rb', line 419

def reference
  default? ? "#{value}.id" : value
end