Class: Rufio::Config
- Inherits:
-
Object
- Object
- Rufio::Config
- Defined in:
- lib/rufio/config.rb
Constant Summary collapse
- DEFAULT_LANGUAGE =
Default language settings
'en'- AVAILABLE_LANGUAGES =
%w[en ja].freeze
- CONFIG_DIR =
設定ディレクトリとファイルパス
File.('~/.config/rufio').freeze
- CONFIG_RB_PATH =
File.join(CONFIG_DIR, 'config.rb').freeze
- SCRIPT_PATHS_YML =
File.join(CONFIG_DIR, 'script_paths.yml').freeze
- BOOKMARKS_YML =
File.join(CONFIG_DIR, 'bookmarks.yml').freeze
- YAML_CONFIG_PATH =
後方互換性のためのパス(非推奨)
File.join(CONFIG_DIR, 'config.yml').freeze
- LOCAL_YAML_PATH =
'./rufio.yml'- MESSAGES =
Multi-language message definitions
{ 'en' => { # Application messages 'app.interrupted' => 'rufio interrupted', 'app.error_occurred' => 'Error occurred', 'app.terminated' => 'rufio terminated', # File operations 'file.not_found' => 'File not found', 'file.not_readable' => 'File not readable', 'file.read_error' => 'File read error', 'file.binary_file' => 'Binary file', 'file.cannot_preview' => 'Cannot preview', 'file.encoding_error' => 'Character encoding error - cannot read file', 'file.preview_error' => 'Preview error', 'file.error_prefix' => 'Error', # Keybind messages 'keybind.invalid_key' => 'invalid key', 'keybind.search_text' => 'Search text: ', 'keybind.no_matches' => 'No matches found.', 'keybind.press_any_key' => 'Press any key to continue...', 'keybind.input_filename' => 'Enter filename: ', 'keybind.input_dirname' => 'Enter directory name: ', 'keybind.invalid_filename' => 'Invalid filename (cannot contain / or \\)', 'keybind.invalid_dirname' => 'Invalid directory name (cannot contain / or \\)', 'keybind.file_exists' => 'File already exists', 'keybind.directory_exists' => 'Directory already exists', 'keybind.file_created' => 'File created', 'keybind.directory_created' => 'Directory created', 'keybind.creation_error' => 'Creation error', # UI messages 'ui.operation_prompt' => 'Operation: ', # Help text 'help.full' => 'j/k:move h:back l:enter o:open g/G:top/bottom r:refresh f:filter s:search F:content a/A:create m/p/x:ops b:bookmark z:zoxide 1-9:goto q:quit', 'help.short' => 'j/k:move h:back l:enter o:open f:filter s:search b:bookmark z:zoxide 1-9:goto q:quit', # Health check messages 'health.title' => 'rufio Health Check', 'health.ruby_version' => 'Ruby version', 'health.required_gems' => 'Required gems', 'health.fzf' => 'fzf (file search)', 'health.rga' => 'rga (content search)', 'health.zoxide' => 'zoxide (directory history)', 'health.bat' => 'bat (syntax highlight)', 'health.file_opener' => 'System file opener', 'health.summary' => 'Summary:', 'health.ok' => 'OK', 'health.warnings' => 'Warnings', 'health.errors' => 'Errors', 'health.all_passed' => 'All checks passed! rufio is ready to use.', 'health.critical_missing' => 'Some critical components are missing. rufio may not work properly.', 'health.optional_missing' => 'Some optional features are unavailable. Basic functionality will work.', 'health.all_gems_installed' => 'All required gems installed', 'health.missing_gems' => 'Missing gems', 'health.gem_install_instruction' => 'Run: gem install', 'health.tool_not_found' => 'not found', 'health.unknown_platform' => 'Unknown platform', 'health.file_open_may_not_work' => 'File opening may not work properly', 'health.macos_opener' => 'macOS file opener', 'health.linux_opener' => 'Linux file opener', 'health.windows_opener' => 'Windows file opener', 'health.install_brew' => 'Install: brew install', 'health.install_apt' => 'Install: apt install', 'health.install_guide' => 'Install: Check the installation guide for your platform', 'health.rga_releases' => 'Install: https://github.com/phiresky/ripgrep-all/releases', 'health.ruby_upgrade_needed' => 'Please upgrade Ruby to version 2.7.0 or higher' }, 'ja' => { # Application messages 'app.interrupted' => 'rufio interrupted', 'app.error_occurred' => 'Error occurred', 'app.terminated' => 'rufio terminated', # File operations 'file.not_found' => 'File not found', 'file.not_readable' => 'File not readable', 'file.read_error' => 'File read error', 'file.binary_file' => 'Binary file', 'file.cannot_preview' => 'Cannot preview', 'file.encoding_error' => 'Encoding error - cannot read file', 'file.preview_error' => 'Preview error', 'file.error_prefix' => 'Error', # Keybind messages 'keybind.invalid_key' => 'Invalid key', 'keybind.search_text' => 'Search: ', 'keybind.no_matches' => 'No matches found.', 'keybind.press_any_key' => 'Press any key to continue...', 'keybind.input_filename' => 'Enter filename: ', 'keybind.input_dirname' => 'Enter directory name: ', 'keybind.invalid_filename' => 'Invalid filename (cannot contain / or \\)', 'keybind.invalid_dirname' => 'Invalid directory name (cannot contain / or \\)', 'keybind.file_exists' => 'File already exists', 'keybind.directory_exists' => 'Directory already exists', 'keybind.file_created' => 'File created', 'keybind.directory_created' => 'Directory created', 'keybind.creation_error' => 'Creation error', # UI messages 'ui.operation_prompt' => 'Operation: ', # Help text 'help.full' => 'j/k:move h:back l:enter o:open g/G:top/end r:refresh f:filter s:search F:content a/A:create m/c/x:ops b:bookmark z:zoxide 1-9:jump q:quit', 'help.short' => 'j/k:move h:back l:enter o:open f:filter s:search b:bookmark z:zoxide 1-9:jump q:quit', # Health check messages 'health.title' => 'rufio Health Check', 'health.ruby_version' => 'Ruby version', 'health.required_gems' => 'Required gems', 'health.fzf' => 'fzf (file search)', 'health.rga' => 'rga (content search)', 'health.zoxide' => 'zoxide (directory history)', 'health.bat' => 'bat (syntax highlight)', 'health.file_opener' => 'System file opener', 'health.summary' => 'Summary:', 'health.ok' => 'OK', 'health.warnings' => 'Warnings', 'health.errors' => 'Errors', 'health.all_passed' => 'All checks passed! rufio is ready to use.', 'health.critical_missing' => 'Critical components missing. rufio may not work properly.', 'health.optional_missing' => 'Optional features unavailable. Basic features will work.', 'health.all_gems_installed' => 'All required gems are installed', 'health.missing_gems' => 'Missing gems', 'health.gem_install_instruction' => 'Run: gem install', 'health.tool_not_found' => 'not found', 'health.unknown_platform' => 'Unknown platform', 'health.file_open_may_not_work' => 'File open may not work properly', 'health.macos_opener' => 'macOS file opener', 'health.linux_opener' => 'Linux file opener', 'health.windows_opener' => 'Windows file opener', 'health.install_brew' => 'Install: brew install', 'health.install_apt' => 'Install: apt install', 'health.install_guide' => 'Install: Check the installation guide for your platform', 'health.rga_releases' => 'Install: https://github.com/phiresky/ripgrep-all/releases', 'health.ruby_upgrade_needed' => 'Please upgrade Ruby to version 2.7.0 or higher' } }.freeze
Class Method Summary collapse
-
.add_bookmark(path, bookmark_path, name) ⇒ Object
ブックマークを追加.
-
.add_script_path(path, new_path) ⇒ Object
スクリプトパスを追加.
- .available_languages ⇒ Object
- .current_language ⇒ Object
- .current_language=(lang) ⇒ Object
-
.load_bookmarks_from_yml(path = BOOKMARKS_YML) ⇒ Array<Hash>
ブックマークを読み込む.
-
.load_config_rb(path = CONFIG_RB_PATH) ⇒ Object
config.rb を読み込む.
-
.load_script_paths(path = SCRIPT_PATHS_YML) ⇒ Array<String>
スクリプトパスを読み込む.
-
.load_yaml_config(path) ⇒ Hash
YAML設定ファイルを読み込む.
- .message(key, **interpolations) ⇒ Object
-
.migrate_from_config_yml(old_config_yml, script_paths_yml, bookmarks_yml) ⇒ Object
古い config.yml から新形式にマイグレーション.
-
.reload_yaml_config! ⇒ Object
YAML設定をリロード.
-
.remove_bookmark(path, name) ⇒ Object
ブックマークを削除.
-
.remove_script_path(path, remove_path) ⇒ Object
スクリプトパスを削除.
-
.reset_config! ⇒ Object
全設定をリセット.
- .reset_language! ⇒ Object
-
.save_bookmarks_to_yml(path, bookmarks) ⇒ Object
ブックマークを保存.
-
.save_script_paths(path, paths) ⇒ Object
スクリプトパスを保存.
-
.save_yaml_config(path, key, value) ⇒ Object
YAML設定ファイルにセクションを保存.
-
.yaml_config ⇒ Hash
YAML設定を取得(キャッシュあり).
Class Method Details
.add_bookmark(path, bookmark_path, name) ⇒ Object
ブックマークを追加
296 297 298 299 300 |
# File 'lib/rufio/config.rb', line 296 def add_bookmark(path, bookmark_path, name) bookmarks = load_bookmarks_from_yml(path) bookmarks << { path: bookmark_path, name: name } save_bookmarks_to_yml(path, bookmarks) end |
.add_script_path(path, new_path) ⇒ Object
スクリプトパスを追加
245 246 247 248 249 250 251 252 |
# File 'lib/rufio/config.rb', line 245 def add_script_path(path, new_path) paths = load_script_paths(path) = File.(new_path) return if paths.include?() paths << save_script_paths(path, paths) end |
.available_languages ⇒ Object
189 190 191 |
# File 'lib/rufio/config.rb', line 189 def available_languages AVAILABLE_LANGUAGES.dup end |
.current_language ⇒ Object
166 167 168 |
# File 'lib/rufio/config.rb', line 166 def current_language @current_language ||= detect_language end |
.current_language=(lang) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/rufio/config.rb', line 170 def current_language=(lang) if AVAILABLE_LANGUAGES.include?(lang.to_s) @current_language = lang.to_s else raise ArgumentError, "Unsupported language: #{lang}. Available: #{AVAILABLE_LANGUAGES.join(', ')}" end end |
.load_bookmarks_from_yml(path = BOOKMARKS_YML) ⇒ Array<Hash>
ブックマークを読み込む
271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/rufio/config.rb', line 271 def load_bookmarks_from_yml(path = BOOKMARKS_YML) return [] unless File.exist?(path) yaml = YAML.safe_load(File.read(path), symbolize_names: true) return [] unless yaml.is_a?(Array) yaml.select { |b| b.is_a?(Hash) && b[:path] && b[:name] } rescue StandardError => e warn "Failed to load bookmarks: #{e.}" [] end |
.load_config_rb(path = CONFIG_RB_PATH) ⇒ Object
config.rb を読み込む
317 318 319 320 321 322 323 |
# File 'lib/rufio/config.rb', line 317 def load_config_rb(path = CONFIG_RB_PATH) return unless File.exist?(path) load path rescue StandardError => e warn "Failed to load config.rb: #{e.}" end |
.load_script_paths(path = SCRIPT_PATHS_YML) ⇒ Array<String>
スクリプトパスを読み込む
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/rufio/config.rb', line 222 def load_script_paths(path = SCRIPT_PATHS_YML) return [] unless File.exist?(path) yaml = YAML.safe_load(File.read(path)) return [] unless yaml.is_a?(Array) yaml.map { |p| File.(p) } rescue StandardError => e warn "Failed to load script paths: #{e.}" [] end |
.load_yaml_config(path) ⇒ Hash
YAML設定ファイルを読み込む
352 353 354 355 356 357 358 359 360 |
# File 'lib/rufio/config.rb', line 352 def load_yaml_config(path) return {} unless File.exist?(path) yaml = YAML.safe_load(File.read(path), symbolize_names: true) yaml || {} rescue StandardError => e warn "Failed to load YAML config: #{e.}" {} end |
.message(key, **interpolations) ⇒ Object
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rufio/config.rb', line 178 def (key, **interpolations) msg = MESSAGES.dig(current_language, key) || MESSAGES.dig(DEFAULT_LANGUAGE, key) || key # Simple interpolation support interpolations.each do |placeholder, value| msg = msg.gsub("%{#{placeholder}}", value.to_s) end msg end |
.migrate_from_config_yml(old_config_yml, script_paths_yml, bookmarks_yml) ⇒ Object
古い config.yml から新形式にマイグレーション
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/rufio/config.rb', line 333 def migrate_from_config_yml(old_config_yml, script_paths_yml, bookmarks_yml) return unless File.exist?(old_config_yml) old_config = load_yaml_config(old_config_yml) # script_paths のマイグレーション if old_config[:script_paths].is_a?(Array) && !old_config[:script_paths].empty? save_script_paths(script_paths_yml, old_config[:script_paths]) end # bookmarks のマイグレーション if old_config[:bookmarks].is_a?(Array) && !old_config[:bookmarks].empty? save_bookmarks_to_yml(bookmarks_yml, old_config[:bookmarks]) end end |
.reload_yaml_config! ⇒ Object
YAML設定をリロード
204 205 206 |
# File 'lib/rufio/config.rb', line 204 def reload_yaml_config! @yaml_config = nil end |
.remove_bookmark(path, name) ⇒ Object
ブックマークを削除
305 306 307 308 309 |
# File 'lib/rufio/config.rb', line 305 def remove_bookmark(path, name) bookmarks = load_bookmarks_from_yml(path) bookmarks.reject! { |b| b[:name] == name } save_bookmarks_to_yml(path, bookmarks) end |
.remove_script_path(path, remove_path) ⇒ Object
スクリプトパスを削除
257 258 259 260 261 262 |
# File 'lib/rufio/config.rb', line 257 def remove_script_path(path, remove_path) paths = load_script_paths(path) = File.(remove_path) paths.delete() save_script_paths(path, paths) end |
.reset_config! ⇒ Object
全設定をリセット
209 210 211 212 213 |
# File 'lib/rufio/config.rb', line 209 def reset_config! @yaml_config = nil @script_paths = nil @bookmarks = nil end |
.reset_language! ⇒ Object
193 194 195 |
# File 'lib/rufio/config.rb', line 193 def reset_language! @current_language = nil end |
.save_bookmarks_to_yml(path, bookmarks) ⇒ Object
ブックマークを保存
286 287 288 289 290 |
# File 'lib/rufio/config.rb', line 286 def save_bookmarks_to_yml(path, bookmarks) ensure_config_directory(path) data = bookmarks.map { |b| { 'path' => b[:path], 'name' => b[:name] } } File.write(path, YAML.dump(data)) end |
.save_script_paths(path, paths) ⇒ Object
スクリプトパスを保存
237 238 239 240 |
# File 'lib/rufio/config.rb', line 237 def save_script_paths(path, paths) ensure_config_directory(path) File.write(path, YAML.dump(paths)) end |
.save_yaml_config(path, key, value) ⇒ Object
YAML設定ファイルにセクションを保存
366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/rufio/config.rb', line 366 def save_yaml_config(path, key, value) ensure_config_directory(path) existing = if File.exist?(path) YAML.safe_load(File.read(path), symbolize_names: true) || {} else {} end existing[key.to_sym] = value File.write(path, YAML.dump(stringify_keys(existing))) reload_yaml_config! if path == YAML_CONFIG_PATH end |
.yaml_config ⇒ Hash
YAML設定を取得(キャッシュあり)
199 200 201 |
# File 'lib/rufio/config.rb', line 199 def yaml_config @yaml_config ||= load_yaml_config(YAML_CONFIG_PATH) end |