Class: Ptimelog::Configuration
- Inherits:
-
Object
- Object
- Ptimelog::Configuration
- Includes:
- Singleton
- Defined in:
- lib/ptimelog/configuration.rb
Overview
Wrapper around configuration-options and -loading
Constant Summary collapse
- CONFIGURATION_DEFAULTS =
{ 'base_url' => 'https://time.puzzle.ch', 'rounding' => 15, 'dir' => '~/.config/ptimelog', 'timelog' => '~/.local/share/gtimelog/timelog.txt', }.freeze
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_config(fn) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Configuration
19 20 21 |
# File 'lib/ptimelog/configuration.rb', line 19 def initialize reset end |
Instance Method Details
#[](key) ⇒ Object
39 40 41 |
# File 'lib/ptimelog/configuration.rb', line 39 def [](key) @config[key.to_s] end |
#[]=(key, value) ⇒ Object
43 44 45 46 47 |
# 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) ⇒ Object
33 34 35 36 37 |
# 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 ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/ptimelog/configuration.rb', line 23 def reset @config = load_config( Pathname.new(CONFIGURATION_DEFAULTS['dir']) . .join('config') ) wrap_with_pathname('dir') wrap_with_pathname('timelog') end |