Class: Rufio::ConfigLoader
- Inherits:
-
Object
- Object
- Rufio::ConfigLoader
- Defined in:
- lib/rufio/config_loader.rb
Constant Summary collapse
- CONFIG_PATH =
新しいパス定数(Configから取得)
Config::CONFIG_RB_PATH
- SCRIPT_PATHS_YML =
Config::SCRIPT_PATHS_YML
- BOOKMARKS_YML =
Config::BOOKMARKS_YML
- YAML_CONFIG_PATH =
後方互換性のためのパス(非推奨)
Config::YAML_CONFIG_PATH
- LOCAL_YAML_PATH =
Config::LOCAL_YAML_PATH
Class Method Summary collapse
-
.add_script_path(path) ⇒ Boolean
スクリプトパスを追加.
- .applications ⇒ Object
-
.bookmark_storage ⇒ YamlBookmarkStorage
ブックマークストレージを取得.
- .colors ⇒ Object
- .command_history_size ⇒ Object
-
.default_keybinds ⇒ Object
デフォルトキーバインド(全アクションの単一キー定義).
-
.default_script_paths ⇒ Array<String>
デフォルトのスクリプトパス.
- .default_scripts_dir ⇒ Object
-
.default_ui_options ⇒ Object
デフォルトUI設定.
-
.expand_script_paths(paths) ⇒ Array<String>
スクリプトパスを展開.
- .keybinds ⇒ Object
- .language ⇒ Object
-
.load_bookmarks ⇒ Array<Hash>
ブックマークを読み込む(新形式: bookmarks.yml).
- .load_config ⇒ Object
-
.load_yaml_config(path = nil) ⇒ Hash
YAML設定ファイルを読み込む(Config経由).
- .message(key, **interpolations) ⇒ Object
-
.migrate_bookmarks_if_needed ⇒ Object
古いconfig.ymlからのマイグレーション.
- .reload_config! ⇒ Object
-
.remove_script_path(path) ⇒ Boolean
スクリプトパスを削除.
-
.save_bookmarks(bookmarks) ⇒ Boolean
ブックマークを保存(新形式: bookmarks.yml).
-
.script_paths ⇒ Array<String>
スクリプトパスの配列を取得(ローカル > ユーザー設定の優先順位でマージ).
- .scripts_dir ⇒ Object
- .set_language(lang) ⇒ Object
-
.ui_options ⇒ Object
UI設定(デフォルト+ユーザー設定のマージ).
Class Method Details
.add_script_path(path) ⇒ Boolean
スクリプトパスを追加
152 153 154 155 156 157 158 159 160 |
# File 'lib/rufio/config_loader.rb', line 152 def add_script_path(path) = File.(path) current = script_paths return false if current.include?() save_script_paths_to_yaml(current + []) @script_paths = nil true end |
.applications ⇒ Object
33 34 35 |
# File 'lib/rufio/config_loader.rb', line 33 def applications load_config[:applications] end |
.bookmark_storage ⇒ YamlBookmarkStorage
ブックマークストレージを取得
208 209 210 |
# File 'lib/rufio/config_loader.rb', line 208 def bookmark_storage @bookmark_storage ||= YamlBookmarkStorage.new(BOOKMARKS_YML) end |
.colors ⇒ Object
37 38 39 |
# File 'lib/rufio/config_loader.rb', line 37 def colors load_config[:colors] end |
.command_history_size ⇒ Object
126 127 128 |
# File 'lib/rufio/config_loader.rb', line 126 def command_history_size load_config[:command_history_size] || 1000 end |
.default_keybinds ⇒ Object
デフォルトキーバインド(全アクションの単一キー定義)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rufio/config_loader.rb', line 42 def default_keybinds { # ナビゲーション move_up: 'k', move_down: 'j', navigate_parent: 'h', navigate_enter: 'l', top: 'g', bottom: 'G', refresh: 'R', # ファイル操作 open_file: 'o', rename: 'r', delete: 'd', create_file: 'a', create_dir: 'A', move_selected: 'm', copy_selected: 'c', delete_selected: 'x', open_explorer: 'e', # 選択・検索 select: ' ', filter: 'f', fzf_search: 's', fzf_search_alt: '/', rga_search: 'F', # ブックマーク add_bookmark: 'b', bookmark_menu: 'B', zoxide: 'z', start_dir: '0', # モード・ツール job_mode: 'J', help: '?', log_viewer: 'L', command_mode: ':', quit: 'q' }.freeze end |
.default_script_paths ⇒ Array<String>
デフォルトのスクリプトパス
138 139 140 |
# File 'lib/rufio/config_loader.rb', line 138 def default_script_paths [File.('~/.config/rufio/scripts')] end |
.default_scripts_dir ⇒ Object
122 123 124 |
# File 'lib/rufio/config_loader.rb', line 122 def default_scripts_dir File.('~/.config/rufio/scripts') end |
.default_ui_options ⇒ Object
デフォルトUI設定
83 84 85 86 87 88 |
# File 'lib/rufio/config_loader.rb', line 83 def { panel_ratio: 0.5, # 左パネル幅比率(0.3〜0.7) preview_enabled: true # ファイルプレビューのON/OFF }.freeze end |
.expand_script_paths(paths) ⇒ Array<String>
スクリプトパスを展開
145 146 147 |
# File 'lib/rufio/config_loader.rb', line 145 def (paths) paths.map { |p| File.(p) } end |
.keybinds ⇒ Object
96 97 98 99 100 101 |
# File 'lib/rufio/config_loader.rb', line 96 def keybinds raw_user_keybinds = load_config[:keybinds] || {} # 新フォーマット(単一文字列値)のみ受け入れ、古いフォーマット(配列値)は無視 user_keybinds = raw_user_keybinds.select { |_, v| v.is_a?(String) } default_keybinds.merge(user_keybinds) end |
.language ⇒ Object
103 104 105 |
# File 'lib/rufio/config_loader.rb', line 103 def language load_config[:language] || Config.current_language end |
.load_bookmarks ⇒ Array<Hash>
ブックマークを読み込む(新形式: bookmarks.yml)
185 186 187 188 189 190 191 192 193 |
# File 'lib/rufio/config_loader.rb', line 185 def load_bookmarks # 新形式を優先 bookmarks = Config.load_bookmarks_from_yml(BOOKMARKS_YML) return bookmarks unless bookmarks.empty? # 後方互換: 古いconfig.ymlから読み込み yaml_config = load_yaml_config filter_valid_bookmarks(yaml_config[:bookmarks] || []) end |
.load_config ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rufio/config_loader.rb', line 19 def load_config @config ||= if File.exist?(CONFIG_PATH) load_config_file else default_config end end |
.load_yaml_config(path = nil) ⇒ Hash
YAML設定ファイルを読み込む(Config経由)
178 179 180 181 |
# File 'lib/rufio/config_loader.rb', line 178 def load_yaml_config(path = nil) config_path = path || YAML_CONFIG_PATH Config.load_yaml_config(config_path) end |
.message(key, **interpolations) ⇒ Object
114 115 116 |
# File 'lib/rufio/config_loader.rb', line 114 def (key, **interpolations) Config.(key, **interpolations) end |
.migrate_bookmarks_if_needed ⇒ Object
古いconfig.ymlからのマイグレーション
213 214 215 216 217 218 219 |
# File 'lib/rufio/config_loader.rb', line 213 def migrate_bookmarks_if_needed # 新形式が存在する場合はスキップ return if File.exist?(BOOKMARKS_YML) return unless File.exist?(YAML_CONFIG_PATH) Config.migrate_from_config_yml(YAML_CONFIG_PATH, SCRIPT_PATHS_YML, BOOKMARKS_YML) end |
.reload_config! ⇒ Object
27 28 29 30 31 |
# File 'lib/rufio/config_loader.rb', line 27 def reload_config! @config = nil @script_paths = nil load_config end |
.remove_script_path(path) ⇒ Boolean
スクリプトパスを削除
165 166 167 168 169 170 171 172 173 |
# File 'lib/rufio/config_loader.rb', line 165 def remove_script_path(path) = File.(path) current = script_paths return false unless current.include?() save_script_paths_to_yaml(current - []) @script_paths = nil true end |
.save_bookmarks(bookmarks) ⇒ Boolean
ブックマークを保存(新形式: bookmarks.yml)
198 199 200 201 202 203 204 |
# File 'lib/rufio/config_loader.rb', line 198 def save_bookmarks(bookmarks) Config.save_bookmarks_to_yml(BOOKMARKS_YML, bookmarks) true rescue StandardError => e warn "Failed to save bookmarks: #{e.}" false end |
.script_paths ⇒ Array<String>
スクリプトパスの配列を取得(ローカル > ユーザー設定の優先順位でマージ)
132 133 134 |
# File 'lib/rufio/config_loader.rb', line 132 def script_paths @script_paths ||= load_merged_script_paths end |
.scripts_dir ⇒ Object
118 119 120 |
# File 'lib/rufio/config_loader.rb', line 118 def scripts_dir load_config[:scripts_dir] || default_scripts_dir end |
.set_language(lang) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/rufio/config_loader.rb', line 107 def set_language(lang) Config.current_language = lang if @config @config[:language] = lang end end |
.ui_options ⇒ Object
UI設定(デフォルト+ユーザー設定のマージ)
91 92 93 94 |
# File 'lib/rufio/config_loader.rb', line 91 def user_opts = load_config[:ui_options] || {} .merge(user_opts) end |