Class: LightGptProxy::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/light_gpt_proxy/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Config

Returns a new instance of Config.

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/light_gpt_proxy/config.rb', line 5

def initialize(data)
  raise ArgumentError, 'Config data must be a Hash' unless data.is_a?(Hash)

  @data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object (private)



30
31
32
33
34
35
# File 'lib/light_gpt_proxy/config.rb', line 30

def method_missing(symbol, *args)
  key = symbol.to_s
  return data[key] if data.key?(key)

  super
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/light_gpt_proxy/config.rb', line 11

def data
  @data
end

Instance Method Details

#provider(name) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
# File 'lib/light_gpt_proxy/config.rb', line 19

def provider(name)
  return providers_instances[name] if providers_instances[name]

  provider_data = data['providers']&.fetch(name, nil)
  raise ArgumentError, "Provider '#{name}' not found" unless provider_data

  providers_instances[name] = Provider.new(name:, config: provider_data)
end

#providersObject



17
# File 'lib/light_gpt_proxy/config.rb', line 17

def providers = data['providers']&.keys || []

#providers_instancesObject



13
14
15
# File 'lib/light_gpt_proxy/config.rb', line 13

def providers_instances
  @providers_instances ||= {}
end