class SlackPomodoroTimer::Config
Constants
- FILENAME
- PATH
Public Class Methods
add(options={})
click to toggle source
Add a config option or options
# File lib/slack_pomodoro_timer/config.rb, line 35 def self.add(options={}) add_option(:channel, options[:channel]) add_option(:url, options[:url]) end
config()
click to toggle source
Class variable getter returns a hash of config values
# File lib/slack_pomodoro_timer/config.rb, line 15 def self.config @@config end
configured?()
click to toggle source
Returns true if configured properly
# File lib/slack_pomodoro_timer/config.rb, line 22 def self.configured? self.load if @@config.empty? || @@config.any? { |key, value| value.nil? || value.empty? } false else true end end
display()
click to toggle source
Display all config values
# File lib/slack_pomodoro_timer/config.rb, line 72 def self.display if config.empty? puts "No config values set" else config.each do |key, value| puts "#{key.upcase}: #{value}" end end end
get(key)
click to toggle source
Get a config value by key
# File lib/slack_pomodoro_timer/config.rb, line 66 def self.get(key) config[key] end
load()
click to toggle source
Loads the config file if it exists or sets default values if the file does not exist
# File lib/slack_pomodoro_timer/config.rb, line 54 def self.load file_exists = File.exists?(PATH) if File.exists?(PATH) value = YAML.load_file(PATH) else value = defaults end @@config = value end
save()
click to toggle source
Saves the current config hash as YAML to the path
# File lib/slack_pomodoro_timer/config.rb, line 44 def self.save File.open(PATH, 'w+') do |f| f.write(YAML.dump(config)) end end
Private Class Methods
add_option(key, value)
click to toggle source
Sets the key to the given value unless it is nil
# File lib/slack_pomodoro_timer/config.rb, line 98 def self.add_option(key, value) config[key] = value unless value.nil? end
defaults()
click to toggle source
Returns the default config values
# File lib/slack_pomodoro_timer/config.rb, line 88 def self.defaults { :channel => 'general', :url => '', } end