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

32 lines
729 B
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
def attributes(*attributes)
attributes.flatten.each do |attribute|
if method_defined?(attribute)
raise ArgumentError, 'Method already defined!'
end
define_method(attribute) do
return unless config.is_a?(Hash)
config[attribute]
end
2019-10-12 21:52:04 +05:30
define_method("has_#{attribute}?") do
config.is_a?(Hash) && config.key?(attribute)
end
2019-02-15 15:39:39 +05:30
end
end
end
end
end
end
end