Class: NoBrainer::Connection
- Inherits:
-
Object
- Object
- NoBrainer::Connection
- Defined in:
- lib/no_brainer/connection.rb
Instance Attribute Summary collapse
-
#orig_uri ⇒ Object
Returns the value of attribute orig_uri.
-
#parsed_uri ⇒ Object
Returns the value of attribute parsed_uri.
Instance Method Summary collapse
- #current_db ⇒ Object
- #default_db ⇒ Object
-
#initialize(uri) ⇒ Connection
constructor
A new instance of Connection.
- #parse_uri(uri) ⇒ Object
- #raw ⇒ Object (also: #connect)
- #uri ⇒ Object
Constructor Details
#initialize(uri) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 |
# File 'lib/no_brainer/connection.rb', line 7 def initialize(uri) @orig_uri = uri parse_uri(uri) end |
Instance Attribute Details
#orig_uri ⇒ Object
Returns the value of attribute orig_uri.
5 6 7 |
# File 'lib/no_brainer/connection.rb', line 5 def orig_uri @orig_uri end |
#parsed_uri ⇒ Object
Returns the value of attribute parsed_uri.
5 6 7 |
# File 'lib/no_brainer/connection.rb', line 5 def parsed_uri @parsed_uri end |
Instance Method Details
#current_db ⇒ Object
49 50 51 |
# File 'lib/no_brainer/connection.rb', line 49 def current_db NoBrainer.[:db] || default_db end |
#default_db ⇒ Object
45 46 47 |
# File 'lib/no_brainer/connection.rb', line 45 def default_db parsed_uri[:db] end |
#parse_uri(uri) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/no_brainer/connection.rb', line 12 def parse_uri(uri) @parsed_uri = begin uri = URI.parse(uri) if uri.scheme != 'rethinkdb' raise NoBrainer::Error::Connection, "Invalid URI. Expecting something like rethinkdb://host:port/database. Got #{uri}" end { :user => uri.user && CGI.unescape(uri.user), :password => uri.password && CGI.unescape(uri.password), :host => uri.host, :port => uri.port || 28015, :db => uri.path.gsub(/^\//, ''), }.tap { |result| raise "No database specified in #{uri}" unless result[:db].present? } end end |
#raw ⇒ Object Also known as: connect
35 36 37 38 39 |
# File 'lib/no_brainer/connection.rb', line 35 def raw = parsed_uri = .merge(:ssl => NoBrainer::Config.) if NoBrainer::Config. @raw ||= RethinkDB::Connection.new().tap { NoBrainer.logger.info("Connected to #{uri}") } end |
#uri ⇒ Object
31 32 33 |
# File 'lib/no_brainer/connection.rb', line 31 def uri "rethinkdb://#{'****@' if parsed_uri[:password]}#{parsed_uri[:host]}:#{parsed_uri[:port]}/#{parsed_uri[:db]}" end |