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
Returns a new instance of Configuration.
18 19 20 |
# File 'lib/ptimelog/configuration.rb', line 18 def initialize reset end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 |
# File 'lib/ptimelog/configuration.rb', line 36 def [](key) @config[key.to_sym] end |
#[]=(key, value) ⇒ Object
40 41 42 43 44 |
# File 'lib/ptimelog/configuration.rb', line 40 def []=(key, value) @config[key.to_sym] = value wrap_with_pathname(key.to_sym) if %w[dir timelog].include?(key.to_s) end |
#load_config(fn) ⇒ Object
30 31 32 33 34 |
# File 'lib/ptimelog/configuration.rb', line 30 def load_config(fn) user_config = fn.exist? ? YAML.load_file(fn) : {} CONFIGURATION_DEFAULTS.merge(user_config) end |
#reset ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/ptimelog/configuration.rb', line 22 def reset @config = load_config( Pathname.new(CONFIGURATION_DEFAULTS[:dir]).join('config') ) wrap_with_pathname(:dir) wrap_with_pathname(:timelog) end |