Class: AiClient::Config
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- AiClient::Config
- Includes:
- Hashie::Extensions::Mash::DefineAccessors, Hashie::Extensions::Mash::PermissiveRespondTo, Hashie::Extensions::Mash::SymbolizeKeys
- Defined in:
- lib/ai_client/configuration.rb
Constant Summary collapse
- DEFAULT_CONFIG_FILEPATH =
Pathname.new(__dir__) + 'config.yml'
Class Method Summary collapse
-
.load(filepath = DEFAULT_CONFIG_FILEPATH) ⇒ AiClient::Config
Loads configuration from the specified YAML file.
Instance Method Summary collapse
-
#save(filepath = ENV['HOME']+'/aiclient_config.yml') ⇒ Object
Saves the current configuration to the specified file.
Class Method Details
.load(filepath = DEFAULT_CONFIG_FILEPATH) ⇒ AiClient::Config
Loads configuration from the specified YAML file.
115 116 117 118 119 120 121 122 |
# File 'lib/ai_client/configuration.rb', line 115 def load(filepath=DEFAULT_CONFIG_FILEPATH) filepath = Pathname.new(filepath) unless Pathname == filepath.class if filepath.exist? new(YAML.parse(filepath.read).to_ruby) else raise ArgumentError, "#{filepath} does not exist" end end |
Instance Method Details
#save(filepath = ENV['HOME']+'/aiclient_config.yml') ⇒ Object
Saves the current configuration to the specified file.
100 101 102 103 104 |
# File 'lib/ai_client/configuration.rb', line 100 def save(filepath=ENV['HOME']+'/aiclient_config.yml') filepath = Pathname.new(filepath) unless filepath.is_a? Pathname filepath.write(YAML.dump(to_hash)) end |