mongo_light 0.1.2 → 0.1.3
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/document.rb +36 -37
- data/lib/mongo_light/embedded_document.rb +13 -15
- data/lib/mongo_light/version.rb +1 -1
- data/readme.markdown +1 -1
- metadata +2 -2
data/lib/mongo_light/document.rb
CHANGED
|
@@ -53,45 +53,44 @@ module MongoLight
|
|
|
53
53
|
c.find(map(selector)).count
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
end
|
|
56
|
+
|
|
57
|
+
def initialize(attributes = {})
|
|
58
|
+
attributes = {} unless attributes
|
|
59
|
+
@attributes = {:_id => (attributes['_id'] || attributes[:_id] || Id.new)}
|
|
60
|
+
attributes.each do |k,v|
|
|
61
|
+
if self.class.map_include?(k)
|
|
62
|
+
@attributes[k] = v
|
|
63
|
+
elsif k != :_id && k != '_id'
|
|
64
|
+
send("#{k}=", v)
|
|
66
65
|
end
|
|
67
66
|
end
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
67
|
+
end
|
|
68
|
+
def eql?(other)
|
|
69
|
+
other.is_a?(self.class) && id == other.id
|
|
70
|
+
end
|
|
71
|
+
alias :== :eql?
|
|
72
|
+
def hash
|
|
73
|
+
id.hash
|
|
74
|
+
end
|
|
75
|
+
def id
|
|
76
|
+
@attributes[:_id] || @attributes['_id']
|
|
77
|
+
end
|
|
78
|
+
def id=(value)
|
|
79
|
+
@attributes[:_id] = value
|
|
80
|
+
end
|
|
81
|
+
def ==(other)
|
|
82
|
+
other.class == self.class && id == other.id
|
|
83
|
+
end
|
|
84
|
+
def collection
|
|
85
|
+
self.class.collection
|
|
86
|
+
end
|
|
87
|
+
def save(options = nil)
|
|
88
|
+
opts = !options || options.include?(:safe) ? options : {:safe => options}
|
|
89
|
+
opts[:safe].delete(:w) if MongoLight.configuration.skip_replica_concern && opts && opts.include?(:safe) && opts[:safe].is_a?(Hash)
|
|
90
|
+
collection.save(self.class.map(@attributes), opts || {})
|
|
91
|
+
end
|
|
92
|
+
def save!(options = {})
|
|
93
|
+
save({:safe => true}.merge(options))
|
|
95
94
|
end
|
|
96
95
|
end
|
|
97
96
|
end
|
|
@@ -68,23 +68,21 @@ module MongoLight
|
|
|
68
68
|
@map.include?(key)
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
send("#{k}=", v)
|
|
79
|
-
end
|
|
71
|
+
def initialize(attributes = {})
|
|
72
|
+
@attributes = {}
|
|
73
|
+
attributes.each do |k,v|
|
|
74
|
+
if self.class.map_include?(k)
|
|
75
|
+
@attributes[k] = v
|
|
76
|
+
else
|
|
77
|
+
send("#{k}=", v)
|
|
80
78
|
end
|
|
81
79
|
end
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
end
|
|
81
|
+
def [](name)
|
|
82
|
+
@attributes[name]
|
|
83
|
+
end
|
|
84
|
+
def attributes
|
|
85
|
+
@attributes
|
|
88
86
|
end
|
|
89
87
|
end
|
|
90
88
|
end
|
data/lib/mongo_light/version.rb
CHANGED
data/readme.markdown
CHANGED
|
@@ -15,7 +15,7 @@ Configure MongoLight via `MongoLight.configure`:
|
|
|
15
15
|
|
|
16
16
|
This'll automatically handle Passenger forking issues (if Passenger is running).
|
|
17
17
|
|
|
18
|
-
## replica
|
|
18
|
+
## replica concern and testing ##
|
|
19
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)`. (For example, you could do `config.skip_replica_concern = Rails.env.test?`)
|
|
20
20
|
|
|
21
21
|
## Documents ##
|
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.1.
|
|
4
|
+
version: 0.1.3
|
|
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:
|
|
12
|
+
date: 2012-03-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description:
|
|
15
15
|
email:
|