class Ptimelog::Configuration

Wrapper around configuration-options and -loading

Constants

CONFIGURATION_DEFAULTS

Public Class Methods

new() click to toggle source
# File lib/ptimelog/configuration.rb, line 19
def initialize
  reset
end

Public Instance Methods

[](key) click to toggle source
# File lib/ptimelog/configuration.rb, line 39
def [](key)
  @config[key.to_s]
end
[]=(key, value) click to toggle source
# File lib/ptimelog/configuration.rb, line 43
def []=(key, value)
  @config[key.to_s] = value

  wrap_with_pathname(key.to_s) if %w[dir timelog].include?(key.to_s)
end
load_config(fn) click to toggle source
# File lib/ptimelog/configuration.rb, line 33
def load_config(fn)
  user_config = fn.exist? ? YAML.load_file(fn) : {}

  CONFIGURATION_DEFAULTS.merge(user_config)
end
reset() click to toggle source
# File lib/ptimelog/configuration.rb, line 23
def reset
  @config = load_config(
    Pathname.new(CONFIGURATION_DEFAULTS['dir'])
            .expand_path
            .join('config')
  )
  wrap_with_pathname('dir')
  wrap_with_pathname('timelog')
end

Private Instance Methods

wrap_with_pathname(key) click to toggle source
# File lib/ptimelog/configuration.rb, line 51
def wrap_with_pathname(key)
  return unless @config.key?(key)
  return @config[key] if @config[key].is_a? Pathname

  @config[key] = Pathname.new(@config[key]).expand_path
end