mongo_light 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ module MongoLight
2
+ class Configuration
3
+ attr_accessor :connection, :database, :skip_replica_concern
4
+
5
+ def initialize
6
+ @skip_replica_concern = false
7
+ end
8
+ end
9
+ end
@@ -2,10 +2,10 @@ require 'mongo'
2
2
 
3
3
  module MongoLight
4
4
  module Connection
5
-
6
- def self.setup(connection, database_name)
7
- @@connection = connection
8
- @@database = @@connection.db(database_name)
5
+
6
+ def self.setup(configuration)
7
+ @@connection = configuration.connection
8
+ @@database = @@connection.db(configuration.database)
9
9
  handle_passenger_forking
10
10
  end
11
11
 
@@ -72,6 +72,7 @@ module MongoLight
72
72
  end
73
73
  def save(options = nil)
74
74
  opts = !options || options.include?(:safe) ? options : {:safe => options}
75
+ opts[:safe].delete(:w) if MongoLight.configuration.skip_replica_concern && opts.include?(:safe) && opts[:safe].is_a?(Hash)
75
76
  collection.save(self.class.map(@attributes), opts || {})
76
77
  end
77
78
  def save!(options = {})
@@ -1,3 +1,3 @@
1
1
  module MongoLight
2
- Version = '0.0.5'
2
+ Version = '0.0.6'
3
3
  end
data/lib/mongo_light.rb CHANGED
@@ -1,5 +1,21 @@
1
+ require 'mongo_light/configuration'
1
2
  require 'mongo_light/id'
2
3
  require 'mongo_light/connection'
3
4
  require 'mongo_light/embedded_document'
4
5
  require 'mongo_light/document'
5
- require 'mongo_light/mongo_extensions'
6
+ require 'mongo_light/mongo_extensions'
7
+
8
+ module MongoLight
9
+ class << self
10
+ attr_accessor :configuration
11
+
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def configure
17
+ yield(configuration)
18
+ MongoLight::Connection.setup(configuration)
19
+ end
20
+ end
21
+ end
data/readme.markdown CHANGED
@@ -6,12 +6,18 @@ The only Rails dependency is on ActiveSupport::Concern.
6
6
  The wrapper fits a specific use-case (mine).
7
7
 
8
8
  ## Setup ##
9
- During initialization (such as in an initializer), call `MongoLight::Connection.setup`, supplying 2 parameters. The first is a MongoDB connection (that you get from the core driver). The second parameter is the database name. For example:
9
+ Configure MongoLight via `MongoLight.configure`:
10
10
 
11
- MongoLight::Connection.setup(Mongo::Connection.new, 'test')
11
+ MongoLight.configure do |config|
12
+ config.connection = Mongo::Connection.new
13
+ config.database = 'mongolight_tests'
14
+ end
12
15
 
13
16
  This'll automatically handle Passenger forking issues (if Passenger is running).
14
17
 
18
+ ## replica cocnern and testing ##
19
+ For safe writes, I like to use `w:majority`. However, MongoDB will raise an exception if you use this while not using replica sets. This can make testing code more of a pain than necessary. If you configure MongoLight with `config.skip_replica_concern = true`, then `:w => X` or `:w => :majority` will automatically be stripped when calling `save(:w => majority)` or `save!(:w => 3)`.
20
+
15
21
  ## Documents ##
16
22
  To define a document include `MongoLight::Document` and define your properties using the `mongo_accessor` method:
17
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_light
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-10 00:00:00.000000000 Z
12
+ date: 2011-11-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -18,6 +18,7 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - lib/mongo_light/configuration.rb
21
22
  - lib/mongo_light/connection.rb
22
23
  - lib/mongo_light/document.rb
23
24
  - lib/mongo_light/embedded_document.rb
@@ -52,3 +53,4 @@ signing_key:
52
53
  specification_version: 3
53
54
  summary: A Lightweight ORM for Rails and MongoDB
54
55
  test_files: []
56
+ has_rdoc: