Class: ActiveIntelligence::Config
- Inherits:
-
Object
- Object
- ActiveIntelligence::Config
- Defined in:
- lib/active_intelligence/config.rb
Direct Known Subclasses
Instance Method Summary collapse
- #adapter(key = Rails.env.to_sym) ⇒ Object
- #file ⇒ Object
- #name ⇒ Object
- #path ⇒ Object
- #settings(key = Rails.env.to_sym) ⇒ Object
- #yaml ⇒ Object
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 |
#file ⇒ Object
18 19 20 |
# File 'lib/active_intelligence/config.rb', line 18 def file File.read(Rails.root.join(path)) end |
#name ⇒ Object
22 23 24 |
# File 'lib/active_intelligence/config.rb', line 22 def name self.class.name.split('::')[1].force_encoding('UTF-8') end |
#path ⇒ Object
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
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 |
#yaml ⇒ Object
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 |