class TerminalCal::Config

Constants

APP_DIR
CONFIG_FILE
CONFIG_PATH

Public Class Methods

calendars() click to toggle source
# File lib/terminal_cal/config.rb, line 34
def self.calendars
  read[:calendars] || []
end
clobber() click to toggle source
# File lib/terminal_cal/config.rb, line 38
def self.clobber
  File.delete(CONFIG_PATH)
end
config_template() click to toggle source
# File lib/terminal_cal/config.rb, line 42
def self.config_template
  { calendars: [
      { name: 'Some Calendar',
        source: 'Some URL or file path',
        cache: true,
        cache_life_minutes: 30
      }
    ]
  }.to_yaml
end
load() click to toggle source
# File lib/terminal_cal/config.rb, line 7
    def self.load
      unless File.exist?(CONFIG_PATH)
        FileUtils.mkdir_p(APP_DIR)
        File.write(CONFIG_PATH, config_template)
        FileUtils.touch(CONFIG_PATH)

        msg = <<~MSG
          New config generated at #{CONFIG_PATH}
          Please update config and then try again.
        MSG

        raise TerminalCal::Errors::AppExit, msg
      end

      self.read
    end
read() click to toggle source
# File lib/terminal_cal/config.rb, line 24
def self.read
  YAML.load_file(CONFIG_PATH) || {}
end
write(key, value) click to toggle source
# File lib/terminal_cal/config.rb, line 28
def self.write(key, value)
  config = self.read
  config[key] = value
  File.write(CONFIG_PATH, config.to_yaml)
end