Module: Ukey::Config
- Defined in:
- lib/ukey/config.rb
Overview
reads and writes the configuration for ukey
Class Method Summary collapse
- .config_directory ⇒ Object
- .config_path ⇒ Object
- .device ⇒ Object
- .device=(device_name) ⇒ Object
- .interval ⇒ Object
- .interval=(interval) ⇒ Object
- .load_config ⇒ Object
- .write_config(config) ⇒ Object
Class Method Details
.config_directory ⇒ Object
45 46 47 |
# File 'lib/ukey/config.rb', line 45 def config_directory File.('~/.config/ukey') end |
.config_path ⇒ Object
41 42 43 |
# File 'lib/ukey/config.rb', line 41 def config_path File.join(config_directory, 'ukey.yml') end |
.device ⇒ Object
23 24 25 |
# File 'lib/ukey/config.rb', line 23 def device load_config[:device] || raise(DeviceNotSetError) end |
.device=(device_name) ⇒ Object
18 19 20 21 |
# File 'lib/ukey/config.rb', line 18 def device=(device_name) config = load_config.merge(device: device_name) write_config(config) end |
.interval ⇒ Object
32 33 34 |
# File 'lib/ukey/config.rb', line 32 def interval (load_config[:interval] || 5).to_i end |
.interval=(interval) ⇒ Object
27 28 29 30 |
# File 'lib/ukey/config.rb', line 27 def interval=(interval) config = load_config.merge(interval: interval.to_i) write_config(config) end |
.load_config ⇒ Object
13 14 15 16 |
# File 'lib/ukey/config.rb', line 13 def load_config return {} unless File.exist?(config_path) YAML.load_file(config_path) || {} end |
.write_config(config) ⇒ Object
36 37 38 39 |
# File 'lib/ukey/config.rb', line 36 def write_config(config) FileUtils.mkdir_p(config_directory) File.open(config_path, 'w') { |f| YAML.dump(config, f) } end |