Class: AiClient::Config

Inherits:
Hashie::Mash
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.load(filepath = DEFAULT_CONFIG_FILEPATH) ⇒ AiClient::Config

Loads configuration from the specified YAML file.

Parameters:

  • filepath (String) (defaults to: DEFAULT_CONFIG_FILEPATH)

    The path to the configuration file. Defaults to ‘config.yml’ if not provided.

Returns:

Raises:

  • (ArgumentError)

    If the specified file does not exist.



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.

Parameters:

  • filepath (String) (defaults to: ENV['HOME']+'/aiclient_config.yml')

    The path to the file where the configuration will be saved. Defaults to ‘~/aiclient_config.yml’ if not provided.



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