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 = Rails.env.to_sym) ⇒ Object



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

def adapter(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



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

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

#nameObject



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

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

#pathObject



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

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

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

Raises:

  • (KeyError)


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

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

  return settings
end

#yamlObject



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

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