Class: GitlabInternalEventsCli::Helpers::MetricOptions::EventSelection

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

Overview

Represents the attributes of set of events that depend on the other events in the set

Instance Method Summary collapse

Instance Method Details

#actionsObject



123
124
125
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 123

def actions
  events.map(&:action)
end

#can_filter_when_operated_on?(identifier) ⇒ Boolean

Whether there are any filtering options other than the selected uniqueness constraint

Returns:

  • (Boolean)


156
157
158
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 156

def can_filter_when_operated_on?(identifier)
  supports_operations?(identifier) && filter_options.difference([identifier]).any?
end

#events_nameObject

Very brief summary of the provided events to use in a basic description of the metric This ignores filters for simplicity & skimability



130
131
132
133
134
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 130

def events_name
  return actions.first if actions.length == 1

  "any of #{actions.length} events"
end

#exclude_filter_identifier?(identifier) ⇒ Boolean

Whether none of the events have additional properties and the given identifier is an additional property. In this case, it makes sense to exclude these from the menu to keep the flow simple when the use-case is simple

Returns:

  • (Boolean)


180
181
182
183
184
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 180

def exclude_filter_identifier?(identifier)
  return false if identifier.nil? || Metric::Identifier.new(identifier).default?

  filter_options.empty?
end

#filter_name(identifier) ⇒ Object

Formatted list of filter options for these events, given the provided uniqueness constraint



138
139
140
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 138

def filter_name(identifier)
  filter_options.difference([identifier]).join('/')
end

#filter_optionsObject

We accept different filters for each event, so we want any filter options available for any event



144
145
146
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 144

def filter_options
  events.flat_map(&:available_filters).uniq
end

#operable_identifiersObject

We require the same uniqueness constraint for all events, so we want only the options they have in common



150
151
152
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 150

def operable_identifiers
  [*shared_identifiers, *shared_filters, nil]
end

#shared_filtersObject

Common values for filters shared across all the events



172
173
174
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 172

def shared_filters
  events.map(&:available_filters).reduce(&:&)
end

#shared_identifiersObject

Common values for identifiers shared across all the events



167
168
169
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 167

def shared_identifiers
  events.map(&:identifiers).reduce(&:&)
end

#supports_operations?(identifier) ⇒ Boolean

Whether the given identifier is available for all events and can be used as a uniqueness constraint

Returns:

  • (Boolean)


162
163
164
# File 'lib/gitlab_internal_events_cli/helpers/metric_options.rb', line 162

def supports_operations?(identifier)
  operable_identifiers.include?(identifier)
end