summaryrefslogtreecommitdiff
path: root/lib/feature
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 12:11:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-01 12:11:01 +0000
commit08b3b98051f56cfc1774db5c92c183cf33ed8bdd (patch)
treed93e764b9ac3fd30eaf827a1017fbb40a7abf40c /lib/feature
parenta928c5170fa58e4aef91ebca6c4fc9ec7cea812e (diff)
downloadgitlab-ce-08b3b98051f56cfc1774db5c92c183cf33ed8bdd.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/feature')
-rw-r--r--lib/feature/definition.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/feature/definition.rb b/lib/feature/definition.rb
index b0ea55c5805..ee779a86952 100644
--- a/lib/feature/definition.rb
+++ b/lib/feature/definition.rb
@@ -107,6 +107,20 @@ class Feature
end
end
+ def register_hot_reloader!
+ # Reload feature flags on change of this file or any `.yml`
+ file_watcher = Rails.configuration.file_watcher.new(reload_files, reload_directories) do
+ # We use `Feature::Definition` as on Ruby code-reload
+ # a new class definition is created
+ Feature::Definition.load_all!
+ end
+
+ Rails.application.reloaders << file_watcher
+ Rails.application.reloader.to_run { file_watcher.execute_if_updated }
+
+ file_watcher
+ end
+
private
def load_from_file(path)
@@ -130,6 +144,19 @@ class Feature
definitions[definition.key] = definition
end
end
+
+ def reload_files
+ [File.expand_path(__FILE__)]
+ end
+
+ def reload_directories
+ paths.each_with_object({}) do |path, result|
+ path = File.dirname(path)
+ Dir.glob(path).each do |matching_dir|
+ result[matching_dir] = 'yml'
+ end
+ end
+ end
end
end
end