mongomapper_plugins 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -11,19 +11,16 @@ module MongoMapper
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rescue Mongo::OperationFailure => e
|
23
|
-
#Ignored, trying to get the next key
|
24
|
-
end
|
25
|
-
end
|
14
|
+
def generate_document_id(options={})
|
15
|
+
while true
|
16
|
+
oldest_number = self.class.fields(:_id).sort([[:_id, :descending]]).first.try(:id)
|
17
|
+
self.id = oldest_number.to_i + 1
|
18
|
+
begin
|
19
|
+
break if collection.insert({:_id => id}, :safe => true)
|
20
|
+
rescue Mongo::OperationFailure => e
|
21
|
+
#Ignored, trying to get the next key
|
26
22
|
end
|
23
|
+
end
|
27
24
|
end
|
28
25
|
end
|
29
26
|
end
|
@@ -6,85 +6,83 @@ module MongoMapper
|
|
6
6
|
def self.configure(mod)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
obj.send("#{method}=", value)
|
14
|
-
end
|
15
|
-
super hash_to_mongo(hash)
|
9
|
+
def set(hash)
|
10
|
+
hash.each do |key, value|
|
11
|
+
obj, method = get_obj_and_method(key)
|
12
|
+
obj.send("#{method}=", value)
|
16
13
|
end
|
14
|
+
super hash_to_mongo(hash)
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
super hash_to_mongo(hash)
|
17
|
+
def increment(hash)
|
18
|
+
hash.each do |key, value|
|
19
|
+
obj, method = get_obj_and_method(key)
|
20
|
+
val = obj.send(method)
|
21
|
+
obj.send("#{method}=", val + value)
|
25
22
|
end
|
23
|
+
super hash_to_mongo(hash)
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
super hash_to_mongo(hash)
|
26
|
+
def decrement(hash)
|
27
|
+
hash.each do |key, value|
|
28
|
+
obj, method = get_obj_and_method(key)
|
29
|
+
val = obj.send(method)
|
30
|
+
obj.send("#{method}=", val - value)
|
34
31
|
end
|
32
|
+
super hash_to_mongo(hash)
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
super hash_to_mongo(hash)
|
35
|
+
def push(hash)
|
36
|
+
hash.each do |key, value|
|
37
|
+
obj, method = get_obj_and_method(key)
|
38
|
+
obj = obj.send(method)
|
39
|
+
obj.push value
|
43
40
|
end
|
41
|
+
super hash_to_mongo(hash)
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
super hash_to_mongo(hash)
|
44
|
+
def pull(hash)
|
45
|
+
hash.each do |key, value|
|
46
|
+
obj, method = get_obj_and_method(key)
|
47
|
+
obj = obj.send(method)
|
48
|
+
obj.delete_if { |e| e == value }
|
52
49
|
end
|
50
|
+
super hash_to_mongo(hash)
|
51
|
+
end
|
53
52
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
super hash_to_mongo(hash)
|
53
|
+
def add_to_set(hash)
|
54
|
+
hash.each do |key, value|
|
55
|
+
obj, method = get_obj_and_method(key)
|
56
|
+
obj = obj.send(method)
|
57
|
+
obj.push(value) unless obj.include?(value)
|
61
58
|
end
|
62
|
-
|
59
|
+
super hash_to_mongo(hash)
|
60
|
+
end
|
61
|
+
alias push_uniq add_to_set
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
private
|
64
|
+
def get_obj_and_method(key)
|
65
|
+
children = key.to_s.split(/\./)
|
66
|
+
method = children.pop
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
68
|
+
obj = self
|
69
|
+
children.each do |child|
|
70
|
+
obj = obj.send(child)
|
71
|
+
end
|
73
72
|
|
74
|
-
|
75
|
-
|
73
|
+
[obj, method]
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
arg
|
84
|
-
else
|
85
|
-
arg && arg.respond_to?(:to_mongo) ? arg.to_mongo : arg
|
86
|
-
end
|
76
|
+
def hash_to_mongo(arg)
|
77
|
+
if arg.is_a?(Hash)
|
78
|
+
keys = arg.keys
|
79
|
+
keys.each do |k|
|
80
|
+
arg[k] = hash_to_mongo(arg[k])
|
87
81
|
end
|
82
|
+
arg
|
83
|
+
else
|
84
|
+
arg && arg.respond_to?(:to_mongo) ? arg.to_mongo : arg
|
85
|
+
end
|
88
86
|
end
|
89
87
|
end
|
90
88
|
end
|
@@ -12,18 +12,24 @@ module MongoMapper
|
|
12
12
|
|
13
13
|
module OverriddenMethods
|
14
14
|
private
|
15
|
-
|
16
|
-
|
15
|
+
# Overriding save_to_collection in lib/mongo_mapper/plugins/querying.rb
|
16
|
+
def save_to_collection(options={})
|
17
|
+
if persisted?
|
18
|
+
@_new = false
|
19
|
+
old_version = self._version
|
17
20
|
self._version += 1
|
18
|
-
ret = collection.update({:_id => _id, :_version =>
|
19
|
-
|
20
|
-
|
21
|
+
ret = collection.update({:_id => _id, :_version => old_version},
|
22
|
+
to_mongo,
|
23
|
+
:safe => true)
|
21
24
|
if ret['n'] == 0
|
22
25
|
self._version -= 1
|
23
26
|
raise InvalidVersion
|
24
27
|
end
|
25
28
|
ret['err'].nil?
|
29
|
+
else
|
30
|
+
super
|
26
31
|
end
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
class InvalidVersion < StandardError; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongomapper_plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-02-28 00:00:00.000000000
|
13
|
-
default_executable:
|
12
|
+
date: 2011-02-28 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: bundler
|
17
|
-
requirement: &
|
16
|
+
requirement: &70105439900920 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,7 +21,7 @@ dependencies:
|
|
22
21
|
version: '1.0'
|
23
22
|
type: :development
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *70105439900920
|
26
25
|
description: A repository of MongoMapper plugins.
|
27
26
|
email: andrew@andrewtimberlake.com
|
28
27
|
executables: []
|
@@ -38,7 +37,6 @@ files:
|
|
38
37
|
- lib/mongomapper_plugins/railtie.rb
|
39
38
|
- lib/mongomapper_plugins.rb
|
40
39
|
- README.rdoc
|
41
|
-
has_rdoc: true
|
42
40
|
homepage: http://github.com/andrewtimberlake/mongomapper_plugins
|
43
41
|
licenses: []
|
44
42
|
post_install_message:
|
@@ -60,8 +58,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
58
|
version: '0'
|
61
59
|
requirements: []
|
62
60
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.8.15
|
64
62
|
signing_key:
|
65
63
|
specification_version: 3
|
66
64
|
summary: A repository of MongoMapper plugins.
|
67
65
|
test_files: []
|
66
|
+
has_rdoc:
|