Class: Rufio::ConfigLoader

Inherits:
Object
  • Object
show all
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

Class Method Details

.add_script_path(path) ⇒ Boolean

スクリプトパスを追加

Parameters:

  • path (String)

    追加するパス

Returns:

  • (Boolean)

    追加成功したか



152
153
154
155
156
157
158
159
160
# File 'lib/rufio/config_loader.rb', line 152

def add_script_path(path)
  expanded = File.expand_path(path)
  current = script_paths
  return false if current.include?(expanded)

  save_script_paths_to_yaml(current + [expanded])
  @script_paths = nil
  true
end

.applicationsObject



33
34
35
# File 'lib/rufio/config_loader.rb', line 33

def applications
  load_config[:applications]
end

.bookmark_storageYamlBookmarkStorage

ブックマークストレージを取得

Returns:



208
209
210
# File 'lib/rufio/config_loader.rb', line 208

def bookmark_storage
  @bookmark_storage ||= YamlBookmarkStorage.new(BOOKMARKS_YML)
end

.colorsObject



37
38
39
# File 'lib/rufio/config_loader.rb', line 37

def colors
  load_config[:colors]
end

.command_history_sizeObject



126
127
128
# File 'lib/rufio/config_loader.rb', line 126

def command_history_size
  load_config[:command_history_size] || 1000
end

.default_keybindsObject

デフォルトキーバインド(全アクションの単一キー定義)



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_pathsArray<String>

デフォルトのスクリプトパス

Returns:

  • (Array<String>)

    デフォルトパス



138
139
140
# File 'lib/rufio/config_loader.rb', line 138

def default_script_paths
  [File.expand_path('~/.config/rufio/scripts')]
end

.default_scripts_dirObject



122
123
124
# File 'lib/rufio/config_loader.rb', line 122

def default_scripts_dir
  File.expand_path('~/.config/rufio/scripts')
end

.default_ui_optionsObject

デフォルトUI設定



83
84
85
86
87
88
# File 'lib/rufio/config_loader.rb', line 83

def default_ui_options
  {
    panel_ratio:     0.5,   # 左パネル幅比率(0.3〜0.7)
    preview_enabled: true   # ファイルプレビューのON/OFF
  }.freeze
end

.expand_script_paths(paths) ⇒ Array<String>

スクリプトパスを展開

Parameters:

  • paths (Array<String>)

    パスの配列

Returns:

  • (Array<String>)

    展開済みのパス



145
146
147
# File 'lib/rufio/config_loader.rb', line 145

def expand_script_paths(paths)
  paths.map { |p| File.expand_path(p) }
end

.keybindsObject



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

.languageObject



103
104
105
# File 'lib/rufio/config_loader.rb', line 103

def language
  load_config[:language] || Config.current_language
end

.load_bookmarksArray<Hash>

ブックマークを読み込む(新形式: bookmarks.yml)

Returns:

  • (Array<Hash>)

    ブックマークの配列



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_configObject



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経由)

Parameters:

  • path (String, nil) (defaults to: nil)

    設定ファイルのパス(nilの場合はデフォルト)

Returns:

  • (Hash)

    設定内容



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 message(key, **interpolations)
  Config.message(key, **interpolations)
end

.migrate_bookmarks_if_neededObject

古い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

スクリプトパスを削除

Parameters:

  • path (String)

    削除するパス

Returns:

  • (Boolean)

    削除成功したか



165
166
167
168
169
170
171
172
173
# File 'lib/rufio/config_loader.rb', line 165

def remove_script_path(path)
  expanded = File.expand_path(path)
  current = script_paths
  return false unless current.include?(expanded)

  save_script_paths_to_yaml(current - [expanded])
  @script_paths = nil
  true
end

.save_bookmarks(bookmarks) ⇒ Boolean

ブックマークを保存(新形式: bookmarks.yml)

Parameters:

  • bookmarks (Array<Hash>)

    ブックマークの配列

Returns:

  • (Boolean)

    保存成功したか



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.message}"
  false
end

.script_pathsArray<String>

スクリプトパスの配列を取得(ローカル > ユーザー設定の優先順位でマージ)

Returns:

  • (Array<String>)

    展開済みのスクリプトパス



132
133
134
# File 'lib/rufio/config_loader.rb', line 132

def script_paths
  @script_paths ||= load_merged_script_paths
end

.scripts_dirObject



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_optionsObject

UI設定(デフォルト+ユーザー設定のマージ)



91
92
93
94
# File 'lib/rufio/config_loader.rb', line 91

def ui_options
  user_opts = load_config[:ui_options] || {}
  default_ui_options.merge(user_opts)
end