Class: Gpuzzletime::Configuration
- Inherits:
-
Object
- Object
- Gpuzzletime::Configuration
- Includes:
- Singleton
- Defined in:
- lib/gpuzzletime/configuration.rb
Overview
Wrapper around configuration-options and -loading
Constant Summary collapse
- CONFIGURATION_DEFAULTS =
{ base_url: 'https://time.puzzle.ch', rounding: 15, dir: '~/.config/gpuzzletime', 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.
17 18 19 |
# File 'lib/gpuzzletime/configuration.rb', line 17 def initialize reset end |
Instance Method Details
#[](key) ⇒ Object
35 36 37 |
# File 'lib/gpuzzletime/configuration.rb', line 35 def [](key) @config[key.to_sym] end |
#[]=(key, value) ⇒ Object
39 40 41 42 43 |
# File 'lib/gpuzzletime/configuration.rb', line 39 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
29 30 31 32 33 |
# File 'lib/gpuzzletime/configuration.rb', line 29 def load_config(fn) user_config = fn.exist? ? YAML.load_file(fn) : {} CONFIGURATION_DEFAULTS.merge(user_config) end |
#reset ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/gpuzzletime/configuration.rb', line 21 def reset @config = load_config( Pathname.new(CONFIGURATION_DEFAULTS[:dir]).join('config') ) wrap_with_pathname(:dir) wrap_with_pathname(:timelog) end |