Class: Hiiro::Config
- Inherits:
-
Object
- Object
- Hiiro::Config
- Defined in:
- lib/hiiro/config.rb
Constant Summary collapse
- BASE_DIR =
File.join(Dir.home, '.config/hiiro')
- DATA_DIR =
File.join(Dir.home, '.local/share/hiiro')
Class Method Summary collapse
- .config_dir(subdir = nil) ⇒ Object
- .data_path(relpath = '') ⇒ Object
- .open(file, dir: nil) ⇒ Object
- .path(relpath = '') ⇒ Object
- .plugin_dir ⇒ Object
- .plugin_files ⇒ Object
Class Method Details
.config_dir(subdir = nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/hiiro/config.rb', line 38 def config_dir(subdir=nil) File.join(Dir.home, '.config/hiiro', *[subdir].compact).tap do |config_path| FileUtils.mkdir_p(config_path) unless Dir.exist?(config_path) end end |
.data_path(relpath = '') ⇒ Object
18 19 20 |
# File 'lib/hiiro/config.rb', line 18 def data_path(relpath='') File.join(DATA_DIR, relpath) end |
.open(file, dir: nil) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/hiiro/config.rb', line 7 def open(file, dir: nil) dir_path = File.(dir || '~') full_path = File.(file, dir_path) Dir.chdir(dir_path) system(ENV['EDITOR'] || 'vim', full_path) end |
.path(relpath = '') ⇒ Object
14 15 16 |
# File 'lib/hiiro/config.rb', line 14 def path(relpath='') File.join(BASE_DIR, relpath) end |
.plugin_dir ⇒ Object
34 35 36 |
# File 'lib/hiiro/config.rb', line 34 def plugin_dir config_dir('plugins') end |
.plugin_files ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hiiro/config.rb', line 22 def plugin_files user_files = Dir.glob(File.join(plugin_dir, '*.rb')) user_basenames = user_files.map { |f| File.basename(f) } gem_plugin_dir = File.join(File.('../..', __FILE__), 'plugins') gem_files = Dir.exist?(gem_plugin_dir) ? Dir.glob(File.join(gem_plugin_dir, '*.rb')) : [] fallback_files = gem_files.reject { |f| user_basenames.include?(File.basename(f)) } user_files + fallback_files end |