2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-17 10:35:30 -04:00
|
|
|
# This class extends an OpenStruct object by adding predicate methods to mimic
|
|
|
|
# ActiveRecord access. We rely on the initial values being true or false to
|
|
|
|
# determine whether to define a predicate method because for a newly-added
|
|
|
|
# column that has not been migrated yet, there is no way to determine the
|
2020-03-22 11:09:49 -04:00
|
|
|
# column type without parsing db/structure.sql.
|
2017-06-17 10:35:30 -04:00
|
|
|
module Gitlab
|
|
|
|
class FakeApplicationSettings < OpenStruct
|
2019-03-06 07:12:04 -05:00
|
|
|
include ApplicationSettingImplementation
|
|
|
|
|
2017-06-17 10:35:30 -04:00
|
|
|
# Mimic ActiveRecord predicate methods for boolean values
|
|
|
|
def self.define_predicate_methods(options)
|
|
|
|
options.each do |key, value|
|
|
|
|
next if key.to_s.end_with?('?')
|
|
|
|
next unless [true, false].include?(value)
|
|
|
|
|
|
|
|
define_method "#{key}?" do
|
|
|
|
actual_key = key.to_s.chomp('?')
|
|
|
|
self[actual_key]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-09-11 00:28:03 -04:00
|
|
|
|
|
|
|
def initialize(options = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
FakeApplicationSettings.define_predicate_methods(options)
|
|
|
|
end
|
|
|
|
|
2019-03-06 07:12:04 -05:00
|
|
|
alias_method :read_attribute, :[]
|
|
|
|
alias_method :has_attribute?, :[]
|
2017-06-17 10:35:30 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Gitlab::FakeApplicationSettings.prepend_if_ee('EE::Gitlab::FakeApplicationSettings')
|