Class: Kuzya::Config
- Inherits:
-
Object
- Object
- Kuzya::Config
- Defined in:
- lib/kuzya/config.rb
Constant Summary collapse
- PATH_TO_DIR =
"#{Dir.home}/.kuzya".freeze
- PATH_TO_CONFIG =
"#{Dir.home}/.kuzya/kuzya.yml".freeze
Instance Attribute Summary collapse
-
#shortcuts ⇒ Object
readonly
Returns the value of attribute shortcuts.
Instance Method Summary collapse
- #add(keys) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #remove(keys) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
12 13 14 15 16 |
# File 'lib/kuzya/config.rb', line 12 def initialize FileUtils.mkdir_p(PATH_TO_DIR) # Creates file if not exists FileUtils.touch(PATH_TO_CONFIG) # Creating file if not exists @shortcuts = YAML.load(File.read(PATH_TO_CONFIG)) || {} end |
Instance Attribute Details
#shortcuts ⇒ Object (readonly)
Returns the value of attribute shortcuts.
10 11 12 |
# File 'lib/kuzya/config.rb', line 10 def shortcuts @shortcuts end |
Instance Method Details
#add(keys) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/kuzya/config.rb', line 18 def add(keys) value = keys.pop scan_shortcuts(keys) new_shortcut = build_shortcut(keys, value) @shortcuts.deep_merge!(new_shortcut) save end |
#remove(keys) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/kuzya/config.rb', line 28 def remove(keys) scan_shortcuts(keys) empty_shortcut = build_empty_shortcut(keys) @shortcuts.deep_merge!(empty_shortcut) @shortcuts = Hash.deep_compact(@shortcuts) save end |