debian-mirror-gitlab/lib/gitlab/config/entry/attributable.rb

38 lines
1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module Gitlab
module Config
module Entry
module Attributable
extend ActiveSupport::Concern
class_methods do
2023-03-04 22:38:38 +05:30
def attributes(*attributes, prefix: nil)
2019-02-15 15:39:39 +05:30
attributes.flatten.each do |attribute|
2023-03-04 22:38:38 +05:30
attribute_method = prefix ? "#{prefix}_#{attribute}" : attribute
if method_defined?(attribute_method)
raise ArgumentError, "Method '#{attribute_method}' already defined in '#{name}'"
2019-02-15 15:39:39 +05:30
end
2023-03-04 22:38:38 +05:30
define_method(attribute_method) do
2019-02-15 15:39:39 +05:30
return unless config.is_a?(Hash)
config[attribute]
end
2019-10-12 21:52:04 +05:30
2023-03-04 22:38:38 +05:30
define_method("has_#{attribute_method}?") do
2019-10-12 21:52:04 +05:30
config.is_a?(Hash) && config.key?(attribute)
end
2023-03-17 16:20:25 +05:30
define_method("has_#{attribute_method}_value?") do
config.is_a?(Hash) && config.key?(attribute) && !config[attribute].nil?
end
2019-02-15 15:39:39 +05:30
end
end
end
end
end
end
end