mongo_hq_connector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mongo_hq_connector.rb +33 -0
  2. metadata +57 -0
@@ -0,0 +1,33 @@
1
+ require 'mongo'
2
+
3
+ class MongoHqConnector
4
+ # Connect to a MongoHQ database
5
+ #
6
+ # Example:
7
+ # >> MongoHqConnector.connection('foo')
8
+ # => <#Mongo::Connection ... >
9
+ #
10
+ # Arguments:
11
+ # default_collection: String
12
+ #
13
+
14
+ @@database = nil
15
+
16
+ def self.connection(default_collection)
17
+ return @@database if @@database
18
+
19
+ if ENV['MONGOHQ_URL']
20
+ url = URI.parse(ENV['MONGOHQ_URL'])
21
+ conn = Mongo::Connection.new(url.host, url.port)
22
+ @@database = conn.db(url.path.gsub(/^\//, ''))
23
+ @@database.authenticate(url.user, url.password)
24
+
25
+ @@database
26
+ else
27
+ @@database = Mongo::Connection.new.db(default_collection)
28
+ end
29
+ end
30
+
31
+ VERSION = '0.0.1'
32
+ end
33
+
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_hq_connector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lucas Wilson-Richter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongo
16
+ requirement: &70115166164420 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70115166164420
25
+ description: Connect to a MongoHQ database using the MONGOHQ_URL environment variable
26
+ if it exists, or else a default collection on the local Mongo.
27
+ email: da.maestro@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/mongo_hq_connector.rb
33
+ homepage: http://github.com/lucaswilric/mongo_hq_connector
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.17
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: MongoHQ connector
57
+ test_files: []