Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/application_context.rb')
-rw-r--r--lib/gitlab/application_context.rb18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/gitlab/application_context.rb b/lib/gitlab/application_context.rb
index 0ea52b7b7c8..67fc2ae2fcc 100644
--- a/lib/gitlab/application_context.rb
+++ b/lib/gitlab/application_context.rb
@@ -47,11 +47,16 @@ module Gitlab
Attribute.new(:root_caller_id, String),
Attribute.new(:merge_action_status, String)
].freeze
+ private_constant :APPLICATION_ATTRIBUTES
def self.known_keys
KNOWN_KEYS
end
+ def self.application_attributes
+ APPLICATION_ATTRIBUTES
+ end
+
def self.with_context(args, &block)
application_context = new(**args)
application_context.use(&block)
@@ -79,12 +84,13 @@ module Gitlab
end
def initialize(**args)
- unknown_attributes = args.keys - APPLICATION_ATTRIBUTES.map(&:name)
+ unknown_attributes = args.keys - self.class.application_attributes.map(&:name)
raise ArgumentError, "#{unknown_attributes} are not known keys" if unknown_attributes.any?
@set_values = args.keys
assign_attributes(args)
+ set_attr_readers
end
# rubocop: disable Metrics/CyclomaticComplexity
@@ -122,12 +128,14 @@ module Gitlab
attr_reader :set_values
- APPLICATION_ATTRIBUTES.each do |attr|
- lazy_attr_reader attr.name, type: attr.type
+ def set_attr_readers
+ self.class.application_attributes.each do |attr|
+ self.class.lazy_attr_reader attr.name, type: attr.type
+ end
end
def assign_hash_if_value(hash, attribute_name)
- unless KNOWN_KEYS.include?(attribute_name)
+ unless self.class.known_keys.include?(attribute_name)
raise ArgumentError, "unknown attribute `#{attribute_name}`"
end
@@ -137,7 +145,7 @@ module Gitlab
end
def assign_attributes(values)
- values.slice(*APPLICATION_ATTRIBUTES.map(&:name)).each do |name, value|
+ values.slice(*self.class.application_attributes.map(&:name)).each do |name, value|
instance_variable_set("@#{name}", value)
end
end