2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
# 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
|
|
|
|
# column type without parsing db/schema.rb.
|
|
|
|
module Gitlab
|
|
|
|
class FakeApplicationSettings < OpenStruct
|
2019-07-07 11:18:12 +05:30
|
|
|
include ApplicationSettingImplementation
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
# 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-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
def initialize(options = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
FakeApplicationSettings.define_predicate_methods(options)
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
alias_method :read_attribute, :[]
|
|
|
|
alias_method :has_attribute?, :[]
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Gitlab::FakeApplicationSettings.prepend_if_ee('EE::Gitlab::FakeApplicationSettings')
|