Class: Legion::Extensions::Llm::HashConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/llm/provider.rb

Overview

Lightweight wrapper that lets a plain Hash behave like a Configuration object, responding to method-style accessors (e.g. config.api_key).

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashConfig

Returns a new instance of HashConfig.



9
10
11
# File 'lib/legion/extensions/llm/provider.rb', line 9

def initialize(hash)
  @data = hash.transform_keys(&:to_sym)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/llm/provider.rb', line 17

def method_missing(name, *args)
  key = name.to_sym
  if name.to_s.end_with?('=')
    @data[name.to_s.chomp('=').to_sym] = args.first
  elsif @data.key?(key)
    @data[key]
  end
end

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/legion/extensions/llm/provider.rb', line 13

def respond_to_missing?(name, include_private = false)
  @data.key?(name.to_sym) || super
end