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.
- data/lib/mongo_light/configuration.rb +9 -0
- data/lib/mongo_light/connection.rb +4 -4
- data/lib/mongo_light/document.rb +1 -0
- data/lib/mongo_light/version.rb +1 -1
- data/lib/mongo_light.rb +17 -1
- data/readme.markdown +8 -2
- metadata +4 -2
|
@@ -2,10 +2,10 @@ require 'mongo'
|
|
|
2
2
|
|
|
3
3
|
module MongoLight
|
|
4
4
|
module Connection
|
|
5
|
-
|
|
6
|
-
def self.setup(
|
|
7
|
-
@@connection = connection
|
|
8
|
-
@@database = @@connection.db(
|
|
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
|
|
data/lib/mongo_light/document.rb
CHANGED
|
@@ -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 = {})
|
data/lib/mongo_light/version.rb
CHANGED
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
|
-
|
|
9
|
+
Configure MongoLight via `MongoLight.configure`:
|
|
10
10
|
|
|
11
|
-
MongoLight
|
|
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.
|
|
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-
|
|
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:
|