Class: Navio::Config
- Inherits:
-
Object
- Object
- Navio::Config
- Defined in:
- lib/navio/config.rb
Overview
This class handles the configuration for the Navio project navigator. It allows for loading, saving, and managing URL shortcuts stored in a YAML configuration file.
Constant Summary collapse
- CONFIG_FILE =
".navio.yml"
Instance Method Summary collapse
- #add_shortcut(name, url) ⇒ Object
- #config_path ⇒ Object
- #get_url(shortcut) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #list_shortcuts ⇒ Object
- #remove_shortcut(name) ⇒ Object
- #save_config ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
11 12 13 |
# File 'lib/navio/config.rb', line 11 def initialize @config = load_config end |
Instance Method Details
#add_shortcut(name, url) ⇒ Object
23 24 25 26 27 |
# File 'lib/navio/config.rb', line 23 def add_shortcut(name, url) @config["shortcuts"] ||= {} @config["shortcuts"][name] = url save_config end |
#config_path ⇒ Object
37 38 39 40 41 |
# File 'lib/navio/config.rb', line 37 def config_path path = find_config_in_path(Dir.pwd) path ||= File.join(Dir.home, CONFIG_FILE) path end |
#get_url(shortcut) ⇒ Object
15 16 17 |
# File 'lib/navio/config.rb', line 15 def get_url(shortcut) @config["shortcuts"] && @config["shortcuts"][shortcut] end |
#list_shortcuts ⇒ Object
19 20 21 |
# File 'lib/navio/config.rb', line 19 def list_shortcuts @config["shortcuts"] || {} end |
#remove_shortcut(name) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/navio/config.rb', line 29 def remove_shortcut(name) return false unless @config["shortcuts"] && @config["shortcuts"][name] @config["shortcuts"].delete(name) save_config true end |
#save_config ⇒ Object
43 44 45 46 47 |
# File 'lib/navio/config.rb', line 43 def save_config File.open(config_path, "w") do |file| file.write(YAML.dump(@config)) end end |