Class: Colloquy::Helpers::Scribe::ScribeProxy
- Inherits:
-
Object
- Object
- Colloquy::Helpers::Scribe::ScribeProxy
- Includes:
- Singleton
- Defined in:
- lib/colloquy/helpers/scribe.rb
Instance Method Summary collapse
- #[](identifier) ⇒ Object
- #configure ⇒ Object
- #configure! ⇒ Object
- #configured? ⇒ Boolean
- #connections ⇒ Object
-
#initialize ⇒ ScribeProxy
constructor
A new instance of ScribeProxy.
- #require_scribe_libraries ⇒ Object
- #scribe_configuration_exists? ⇒ Boolean
- #scribe_configuration_file ⇒ Object
- #scribe_configuration_load ⇒ Object
- #scribe_connection(params) ⇒ Object
Constructor Details
#initialize ⇒ ScribeProxy
Returns a new instance of ScribeProxy.
23 24 25 |
# File 'lib/colloquy/helpers/scribe.rb', line 23 def initialize @configured = false end |
Instance Method Details
#[](identifier) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/colloquy/helpers/scribe.rb', line 57 def [](identifier) unless @scribe_connections[identifier.to_sym] raise Colloquy::ScribeConnectionNotFoundException, "A connection for #{identifier} was not found, did you mis-spell or forget to configure it?" end @scribe_connections[identifier.to_sym] end |
#configure ⇒ Object
27 28 29 30 |
# File 'lib/colloquy/helpers/scribe.rb', line 27 def configure return if configured? configure! end |
#configure! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/colloquy/helpers/scribe.rb', line 32 def configure! unless scribe_configuration_file.exist? raise Colloquy::ScribeConfigurationNotFoundException, "Cannot find #{scribe_configuration_file}" end begin require_scribe_libraries rescue LoadError raise Colloquy::ScribeGemsNotFoundException, "Cannot load the scribe gem." end @scribe_connections ||= {} scribe_configuration_load @configured = true end |
#configured? ⇒ Boolean
49 50 51 |
# File 'lib/colloquy/helpers/scribe.rb', line 49 def configured? @configured end |
#connections ⇒ Object
53 54 55 |
# File 'lib/colloquy/helpers/scribe.rb', line 53 def connections @scribe_connections end |
#require_scribe_libraries ⇒ Object
65 66 67 |
# File 'lib/colloquy/helpers/scribe.rb', line 65 def require_scribe_libraries require 'scribe-logger' end |
#scribe_configuration_exists? ⇒ Boolean
91 92 93 |
# File 'lib/colloquy/helpers/scribe.rb', line 91 def scribe_configuration_exists? scribe_configuration_file.exist? end |
#scribe_configuration_file ⇒ Object
69 70 71 |
# File 'lib/colloquy/helpers/scribe.rb', line 69 def scribe_configuration_file Colloquy.root.join('config', 'scribe.yaml') end |
#scribe_configuration_load ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/colloquy/helpers/scribe.rb', line 73 def scribe_configuration_load return unless scribe_configuration_exists? scribe_configuration = File.open(scribe_configuration_file, "r") { |f| YAML.load(f.read) } if scribe_configuration scribe_configuration.each do |identifier, params| @scribe_connections[identifier.to_sym] = scribe_connection(params) end else raise Colloquy::ScribeConfigurationNotFoundException, "Cannot find configuration in #{scribe_configuration_file}. Is it empty?" end end |
#scribe_connection(params) ⇒ Object
87 88 89 |
# File 'lib/colloquy/helpers/scribe.rb', line 87 def scribe_connection(params) Scribe.loggers(params) end |