Class: ActiveIntelligence::Config

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

Direct Known Subclasses

ASR::Config, LLM::Config

Instance Method Summary collapse

Instance Method Details

#adapter(key = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/active_intelligence/config.rb', line 6

def adapter(key = nil)
  key ||= Rails.env.to_sym
  settings = settings(key)

  klass = [
    'ActiveIntelligence',
    name,
    [settings[:adapter].to_s.camelize, 'Adapter'].join
  ].join('::').constantize

  return klass.new(settings)
end

#fileObject



19
20
21
# File 'lib/active_intelligence/config.rb', line 19

def file
  File.read(Rails.root.join(path))
end

#nameObject



23
24
25
# File 'lib/active_intelligence/config.rb', line 23

def name
  self.class.name.split('::')[1].force_encoding('UTF-8')
end

#pathObject



27
28
29
# File 'lib/active_intelligence/config.rb', line 27

def path
  "config/ai/#{name.downcase}.yml"
end

#settings(key = Rails.env.to_sym) ⇒ Object

Raises:

  • (KeyError)


31
32
33
34
35
36
# File 'lib/active_intelligence/config.rb', line 31

def settings(key = Rails.env.to_sym)
  settings = yaml[key]
  raise KeyError, "#{path}: #{key}" unless settings

  return settings
end

#yamlObject



38
39
40
41
42
43
44
45
46
# File 'lib/active_intelligence/config.rb', line 38

def yaml
  return @yaml if @yaml

  erb = ERB.new(file).result
  yaml = YAML.safe_load(erb, aliases: true)
  @yaml = yaml.deep_symbolize_keys

  return @yaml
end