Class: Rufio::ScriptConfigLoader
- Inherits:
-
Object
- Object
- Rufio::ScriptConfigLoader
- Defined in:
- lib/rufio/script_config_loader.rb
Overview
複数の設定ファイルからscript_pathsをロード・マージするクラス優先順位: ローカル > ユーザー > システム
Constant Summary collapse
- DEFAULT_LOCAL_PATH =
デフォルトの設定ファイルパス(新形式: script_paths.yml)
Config::LOCAL_YAML_PATH
- DEFAULT_USER_PATH =
Config::SCRIPT_PATHS_YML
- DEFAULT_SYSTEM_PATH =
'/etc/rufio/script_paths.yml'
Instance Method Summary collapse
-
#initialize(local_path: nil, user_path: nil, system_path: nil) ⇒ ScriptConfigLoader
constructor
A new instance of ScriptConfigLoader.
-
#merged_config ⇒ Hash
全設定をマージして取得.
-
#script_paths ⇒ Array<String>
マージされたscript_pathsを取得.
Constructor Details
#initialize(local_path: nil, user_path: nil, system_path: nil) ⇒ ScriptConfigLoader
Returns a new instance of ScriptConfigLoader.
18 19 20 21 22 |
# File 'lib/rufio/script_config_loader.rb', line 18 def initialize(local_path: nil, user_path: nil, system_path: nil) @local_path = local_path || DEFAULT_LOCAL_PATH @user_path = user_path || DEFAULT_USER_PATH @system_path = system_path || DEFAULT_SYSTEM_PATH end |
Instance Method Details
#merged_config ⇒ Hash
全設定をマージして取得
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rufio/script_config_loader.rb', line 49 def merged_config config = {} # 逆順で読み込み(システム < ユーザー < ローカル) [@system_path, @user_path, @local_path].each do |config_path| next unless config_path && File.exist?(config_path) file_config = load_config(config_path) config = deep_merge(config, file_config) end # script_pathsは特別処理(マージではなく優先順位付き結合) config['script_paths'] = script_paths config end |
#script_paths ⇒ Array<String>
マージされたscript_pathsを取得
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rufio/script_config_loader.rb', line 26 def script_paths paths = [] seen = Set.new # 優先順位順に読み込み(ローカル > ユーザー > システム) [@local_path, @user_path, @system_path].each do |config_path| next unless config_path && File.exist?(config_path) config_paths = load_paths_from_file(config_path) config_paths.each do |path| = File.(path) next if seen.include?() seen.add() paths << end end paths end |