Class: Gitlab::EndpointAttributes::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/endpoint_attributes/config.rb

Defined Under Namespace

Classes: RequestUrgency

Constant Summary collapse

REQUEST_URGENCIES =
[
  RequestUrgency.new(:high, 0.25),
  RequestUrgency.new(:medium, 0.5),
  RequestUrgency.new(:default, 1),
  RequestUrgency.new(:low, 5)
].index_by(&:name).freeze
SUPPORTED_ATTRIBUTES =
%i[feature_category urgency].freeze

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.


15
16
17
18
# File 'lib/gitlab/endpoint_attributes/config.rb', line 15

def initialize
  @default_attributes = {}
  @action_attributes = {}
end

Instance Method Details

#attribute_for_action(action, attribute_name) ⇒ Object


39
40
41
42
43
44
# File 'lib/gitlab/endpoint_attributes/config.rb', line 39

def attribute_for_action(action, attribute_name)
  value = @action_attributes.dig(action.to_s, attribute_name) || @default_attributes[attribute_name]
  # Translate urgency to a representative struct
  value = REQUEST_URGENCIES[value] if attribute_name == :urgency
  value
end

#defined_actionsObject


20
21
22
# File 'lib/gitlab/endpoint_attributes/config.rb', line 20

def defined_actions
  @action_attributes.keys
end

#set(actions, attributes) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/endpoint_attributes/config.rb', line 24

def set(actions, attributes)
  sanitize_attributes!(attributes)

  if actions.empty?
    conflicted = conflicted_attributes(attributes, @default_attributes)
    raise ArgumentError, "Attributes already defined: #{conflicted.join(", ")}" if conflicted.present?

    @default_attributes.merge!(attributes)
  else
    set_attributes_for_actions(actions, attributes)
  end

  nil
end