Class: Ask::LLM::Config

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

Overview

Simple config wrapper without requiring ostruct. Wraps a hash and provides method-based access.

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
# File 'lib/ask/llm/config.rb', line 8

def initialize(hash = {})
  @hash = (hash || {}).transform_keys(&:to_sym)
  # Also accept string keys
  hash.each { |k, v| @hash[k.to_sym] = v if k.is_a?(String) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/ask/llm/config.rb', line 14

def method_missing(name, *args, &block)
  if name.to_s.end_with?("=")
    @hash[name.to_s.chomp("=").to_sym] = args.first
  elsif args.empty?
    @hash.key?(name) ? @hash[name] : nil
  else
    super
  end
end

Instance Method Details

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/ask/llm/config.rb', line 24

def respond_to_missing?(name, include_private = false)
  @hash.key?(name.to_s.sub(/=$/, "").to_sym) || super
end

#to_hObject



28
29
30
# File 'lib/ask/llm/config.rb', line 28

def to_h
  @hash.dup
end