peace_love 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -10,7 +10,7 @@ require 'peace_love/cursor'
10
10
 
11
11
  module PeaceLove
12
12
  class << self
13
- attr_accessor :db
13
+ attr_accessor :db, :connection
14
14
 
15
15
  def collections
16
16
  @collections ||= {}
@@ -19,5 +19,19 @@ module PeaceLove
19
19
  def [](collection_name)
20
20
  collections[collection_name.to_s] ||= PeaceLove::Collection.new( db[collection_name] )
21
21
  end
22
+
23
+ def connect(options)
24
+ options = AngryHash[options]
25
+
26
+ if options.port?
27
+ options.port = options.port.to_i
28
+ end
29
+
30
+ options.delete('adapter') # XXX check?
31
+
32
+ # TODO - support paired servers
33
+ self.connection = Mongo::Connection.new(options.delete('host'), options.delete('port'), options)
34
+ self.db = connection.db(options.database)
35
+ end
22
36
  end
23
37
  end
@@ -0,0 +1,32 @@
1
+ require 'erb'
2
+ require 'yaml'
3
+
4
+ module Rails #:nodoc:
5
+ module PeaceLove #:nodoc:
6
+ class Railtie < Rails::Railtie #:nodoc:
7
+ initializer 'setup db' do
8
+ # use database.yml to setup mongo
9
+ config_file = Rails.root + "config/database.yml"
10
+ if config_file.file?
11
+ settings = YAML.load( ERB.new(config_file.read).result )[Rails.env]
12
+ ::PeaceLove.connect(settings)
13
+ end
14
+ end
15
+
16
+ initializer "check connection" do
17
+ unless ::PeaceLove.db.present?
18
+ cfg_file = Rails.root.join('config/database.yml')
19
+ cfg_file.exist? or raise(<<-EOMSG)
20
+ Unable to connect to mongodb: #{cfg_file} doesn't exist.
21
+ You need to set up a #{cfg_file} looking like\n
22
+ #{Rails.env}:
23
+ database: yourdb
24
+ host: localhost
25
+
26
+ EOMSG
27
+ raise( "Unable to connect to mongodb using #{Rails.root+'config/database.yml'}" )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{peace_love}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lachie Cox"]
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "lib/peace_love/collection.rb",
24
24
  "lib/peace_love/cursor.rb",
25
25
  "lib/peace_love/document.rb",
26
+ "lib/peace_love/railtie.rb",
26
27
  "peace_love.gemspec"
27
28
  ]
28
29
  s.homepage = %q{http://github.com/lachie/peace_love}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lachie Cox
@@ -50,6 +50,7 @@ files:
50
50
  - lib/peace_love/collection.rb
51
51
  - lib/peace_love/cursor.rb
52
52
  - lib/peace_love/document.rb
53
+ - lib/peace_love/railtie.rb
53
54
  - peace_love.gemspec
54
55
  has_rdoc: true
55
56
  homepage: http://github.com/lachie/peace_love