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