Class: Colloquy::Helpers::MySQL::MySQLProxy
- Inherits:
-
Object
- Object
- Colloquy::Helpers::MySQL::MySQLProxy
- Includes:
- Singleton
- Defined in:
- lib/colloquy/helpers/mysql.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :host => "localhost", :port => 3306, :socket => "/tmp/mysql.sock", :username => "root", :password => "", :reconnect => true, :pool => 5}
Instance Method Summary collapse
- #[](identifier) ⇒ Object
- #configuration ⇒ Object
- #configure ⇒ Object
- #configure! ⇒ Object
- #configured? ⇒ Boolean
-
#initialize ⇒ MySQLProxy
constructor
A new instance of MySQLProxy.
- #require_mysql_libraries ⇒ Object
Constructor Details
#initialize ⇒ MySQLProxy
Returns a new instance of MySQLProxy.
26 27 28 |
# File 'lib/colloquy/helpers/mysql.rb', line 26 def initialize @configured = false end |
Instance Method Details
#[](identifier) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/colloquy/helpers/mysql.rb', line 60 def [](identifier) unless @mysql_db_connections[identifier.to_sym] raise Colloquy::MySQLConnectionNotFoundException, "A connection for #{identifier} was not found, did you mis-spell or forget to configure it?" end @mysql_db_connections[identifier.to_sym] end |
#configuration ⇒ Object
68 69 70 |
# File 'lib/colloquy/helpers/mysql.rb', line 68 def configuration @mysql_configuration_entries end |
#configure ⇒ Object
30 31 32 33 |
# File 'lib/colloquy/helpers/mysql.rb', line 30 def configure return if configured? configure! end |
#configure! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/colloquy/helpers/mysql.rb', line 35 def configure! unless mysql_configuration_file.exist? raise Colloquy::MySQLConfigurationNotFoundException, "Cannot find #{mysql_configuration_file}" end begin require_mysql_libraries rescue LoadError raise Colloquy::MySQLGemsNotFoundException, "Cannot load the mysql2 gem." end @mysql_db_connections ||= {} mysql_configuration_load @configured = true end |
#configured? ⇒ Boolean
52 53 54 |
# File 'lib/colloquy/helpers/mysql.rb', line 52 def configured? @configured end |
#require_mysql_libraries ⇒ Object
56 57 58 |
# File 'lib/colloquy/helpers/mysql.rb', line 56 def require_mysql_libraries require "em-synchrony/mysql2" end |