lib/ukey/config.rb in ukey-0.1.1 vs lib/ukey/config.rb in ukey-0.1.2

- old
+ new

@@ -2,10 +2,13 @@ require 'yaml' require 'fileutils' module Ukey + # device not set error class + class DeviceNotSetError < StandardError; end + # reads and writes the configuration for ukey module Config class << self def load_config return {} unless File.exist?(config_path) @@ -16,10 +19,19 @@ config = load_config.merge(device: device_name) write_config(config) end def device - load_config[:device] || raise('Device not set.') + load_config[:device] || raise(DeviceNotSetError) + end + + def interval=(interval) + config = load_config.merge(interval: interval.to_i) + write_config(config) + end + + def interval + (load_config[:interval] || 5).to_i end def write_config(config) FileUtils.mkdir_p(config_directory) File.open(config_path, 'w') { |f| YAML.dump(config, f) }