Class: Mixergy::Config
- Inherits:
-
Object
- Object
- Mixergy::Config
- Defined in:
- lib/mixergy/config.rb
Overview
Configuration handler for Mixergy CLI and API clients. Loads and saves config as YAML, provides hash-like access.
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
Default path for the config file (~/.mixergy)
File.("~/.mixergy")
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
The loaded config data.
-
#filepath ⇒ String
readonly
Path to the config file.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Get a config value by key.
-
#[]=(key, value) ⇒ void
Set a config value by key.
-
#initialize(config_path = DEFAULT_CONFIG_PATH) ⇒ Config
constructor
Create a new Config object and load config from disk.
-
#load ⇒ Hash
Load config from disk.
-
#save ⇒ void
Save current config data to disk.
Constructor Details
#initialize(config_path = DEFAULT_CONFIG_PATH) ⇒ Config
Create a new Config object and load config from disk.
22 23 24 25 |
# File 'lib/mixergy/config.rb', line 22 def initialize(config_path = DEFAULT_CONFIG_PATH) @filepath = config_path @data = load end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns The loaded config data.
18 19 20 |
# File 'lib/mixergy/config.rb', line 18 def data @data end |
#filepath ⇒ String (readonly)
Returns Path to the config file.
16 17 18 |
# File 'lib/mixergy/config.rb', line 16 def filepath @filepath end |
Instance Method Details
#[](key) ⇒ Object?
Get a config value by key.
46 47 48 |
# File 'lib/mixergy/config.rb', line 46 def [](key) @data[key.to_s] end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Set a config value by key.
54 55 56 |
# File 'lib/mixergy/config.rb', line 54 def []=(key, value) @data[key.to_s] = value end |
#load ⇒ Hash
Load config from disk.
29 30 31 32 33 34 35 |
# File 'lib/mixergy/config.rb', line 29 def load if File.exist?(@filepath) YAML.load_file(@filepath) || {} else {} end end |
#save ⇒ void
This method returns an undefined value.
Save current config data to disk.
39 40 41 |
# File 'lib/mixergy/config.rb', line 39 def save File.write(@filepath, YAML.dump(@data)) end |