mongous 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -0
- data/Rakefile +8 -8
- data/lib/mongous/base.rb +8 -7
- data/lib/mongous/document.rb +13 -10
- data/lib/mongous/extention.rb +23 -23
- data/lib/mongous/filter.rb +53 -53
- data/lib/mongous/version.rb +1 -1
- data/mongous.gemspec +3 -3
- data/sample/save_detail_3.rb +1 -1
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a7aef9ade90f7665f9152ca0fce4831c5f9ac3263bba36f1014b2f51d1596fb
|
4
|
+
data.tar.gz: 5b69a145e019b335bb49de2eec293fbe2109ada1d1702dcd58e27e7e918ff408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d81649ab8678859734b621712493adde5d7d0056f532c4abcb0297894442acd1be905b60e725eb85070aa95a75f4c2353d9e54bcbb44fb20346afd398cc3448
|
7
|
+
data.tar.gz: 0e7001c64b912df122d67c1bd67cbc378b6e9974c24b1a94235348c8ed74cd1fa22d4c65eba2d14e7968387ae8ca22ae375ae46ece75faa039cd8d4936cf1bc3
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
AllCops:
|
3
|
+
Exclude:
|
4
|
+
- '.*'
|
5
|
+
- '*'
|
6
|
+
- '*.gemspec'
|
7
|
+
- 'Gemfile*'
|
8
|
+
- 'bin/**'
|
9
|
+
- 'exe/**'
|
10
|
+
- 'config/**/*'
|
11
|
+
- 'spec/**/*'
|
12
|
+
- 'tmp/**/*'
|
13
|
+
- 'vendor/**/*'
|
14
|
+
TargetRubyVersion: 2.7
|
15
|
+
|
16
|
+
Layout/ExtraSpacing:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/SpaceAroundOperators:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Layout/SpaceBeforeFirstArg:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Layout/SpaceInsideParens:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Layout/SpaceInsideRangeLiteral:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Layout/SpaceInsideReferenceBrackets:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Layout/SpaceInsideStringInterpolation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Lint/AmbiguousBlockAssociation:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Lint/EmptyWhen:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Lint/ReturnInVoidContext:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Lint/UselessAssignment:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Metrics/LineLength:
|
56
|
+
Enabled: false
|
57
|
+
Max: 120
|
58
|
+
|
59
|
+
Metrics/MethodLength:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/Documentation:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Style/FrozenStringLiteralComment:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Style/NumericPredicate:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Style/StringLiterals:
|
72
|
+
Enabled: false
|
73
|
+
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ class Bundler::GemHelper
|
|
13
13
|
dest_path = File.join(dir, "#{name}-#{version}.zip")
|
14
14
|
cmnd = "git archive --format zip --prefix=#{name}/ HEAD > #{dest_path}"
|
15
15
|
|
16
|
-
|
16
|
+
_, code = sh_with_status( cmnd )
|
17
17
|
raise "Couldn't archive gem," unless code == 0
|
18
18
|
|
19
19
|
Bundler.ui.confirm "#{name} #{version} archived to #{dest_path}."
|
@@ -23,11 +23,11 @@ class Bundler::GemHelper
|
|
23
23
|
ver = version.to_s
|
24
24
|
|
25
25
|
cmnd = "git push origin #{ver} "
|
26
|
-
|
26
|
+
_, code = sh_with_status( cmnd )
|
27
27
|
raise "Couldn't git push origin." unless code == 0
|
28
28
|
|
29
29
|
cmnd = "git push "
|
30
|
-
|
30
|
+
_, code = sh_with_status( cmnd )
|
31
31
|
raise "Couldn't git push." unless code == 0
|
32
32
|
|
33
33
|
Bundler.ui.confirm "Git Push #{ver}."
|
@@ -43,15 +43,15 @@ class Bundler::GemHelper
|
|
43
43
|
end
|
44
44
|
|
45
45
|
cmnd = "git add #{version_pathname} "
|
46
|
-
|
46
|
+
_, code = sh_with_status( cmnd )
|
47
47
|
raise "Couldn't git add," unless code == 0
|
48
48
|
|
49
49
|
cmnd = "git commit -m '#{new_version}' "
|
50
|
-
|
50
|
+
_, code = sh_with_status( cmnd )
|
51
51
|
raise "Couldn't git commit." unless code == 0
|
52
52
|
|
53
53
|
cmnd = "git tag #{new_version} "
|
54
|
-
|
54
|
+
_, code = sh_with_status( cmnd )
|
55
55
|
raise "Couldn't git tag." unless code == 0
|
56
56
|
|
57
57
|
Bundler.ui.confirm "Update Tags to #{new_version}."
|
@@ -80,14 +80,14 @@ Bundler::GemHelper.new(Dir.pwd).instance_eval do
|
|
80
80
|
|
81
81
|
desc "Update Version Minor"
|
82
82
|
task 'minor' do
|
83
|
-
major, minor,
|
83
|
+
major, minor, _tiny = version.to_s.split('.')
|
84
84
|
new_version = [major, minor.to_i + 1, 0].join('.')
|
85
85
|
update_version( new_version )
|
86
86
|
end
|
87
87
|
|
88
88
|
desc "Update Version Major"
|
89
89
|
task 'major' do
|
90
|
-
major,
|
90
|
+
major, _minor, _tiny = version.to_s.split('.')
|
91
91
|
new_version = [major.to_i + 1, 0, 0].join('.')
|
92
92
|
update_version( new_version )
|
93
93
|
end
|
data/lib/mongous/base.rb
CHANGED
@@ -11,7 +11,7 @@ module Mongous
|
|
11
11
|
def connect( hosts_or_uri = nil, file: nil, mode: nil, loglevel: nil, **options )
|
12
12
|
case hosts_or_uri
|
13
13
|
when Array, String
|
14
|
-
|
14
|
+
hosts_or_uri
|
15
15
|
|
16
16
|
when NilClass
|
17
17
|
if file
|
@@ -46,8 +46,8 @@ module Mongous
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def connect!( hosts_or_uri = nil, **options )
|
49
|
-
|
50
|
-
self.class_variable_set( :@@client,
|
49
|
+
client_ = connect( hosts_or_uri, **options )
|
50
|
+
self.class_variable_set( :@@client, client_ )
|
51
51
|
end
|
52
52
|
|
53
53
|
def document!( *names, **opts )
|
@@ -56,6 +56,7 @@ module Mongous
|
|
56
56
|
names.each do |name|
|
57
57
|
case name
|
58
58
|
when String
|
59
|
+
name
|
59
60
|
when Symbol
|
60
61
|
name = name.to_s
|
61
62
|
else
|
@@ -97,11 +98,11 @@ module Mongous
|
|
97
98
|
self.class_variable_get( :@@client )
|
98
99
|
end
|
99
100
|
|
100
|
-
def client=(
|
101
|
-
if not
|
102
|
-
raise Mongous::Error, "type invalid. : #{
|
101
|
+
def client=( new_client )
|
102
|
+
if not new_client.is_a?( ::Mongo::Client )
|
103
|
+
raise Mongous::Error, "type invalid. : #{ new_client }"
|
103
104
|
end
|
104
|
-
self.class_variable_set( :@@client,
|
105
|
+
self.class_variable_set( :@@client, new_client )
|
105
106
|
end
|
106
107
|
|
107
108
|
def loger
|
data/lib/mongous/document.rb
CHANGED
@@ -15,7 +15,7 @@ module Mongous
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def method_missing( sym, *args, **
|
18
|
+
def method_missing( sym, *args, **_opts, &_block )
|
19
19
|
m = /\A(\w+)([=])?\Z/.match( sym.to_s )
|
20
20
|
if args.size == 0 && m[2].nil?
|
21
21
|
self[ m[1] ]
|
@@ -55,12 +55,12 @@ module Mongous
|
|
55
55
|
|
56
56
|
self.class.fields.each do |label, field|
|
57
57
|
default_value = getvalue_or_callproc( field[:default] )
|
58
|
-
|
58
|
+
must = field[:_attrs].include?(:must)
|
59
59
|
if @doc.has_key?(label)
|
60
60
|
if !having?( @doc[label] )
|
61
61
|
if default_value
|
62
62
|
self[label] = default_value
|
63
|
-
elsif
|
63
|
+
elsif must
|
64
64
|
raise Mongous::Error, "must but unassigned field. : #{ label }"
|
65
65
|
elsif self.class.symbols[:strict]
|
66
66
|
self[label] = nil
|
@@ -69,7 +69,7 @@ module Mongous
|
|
69
69
|
else
|
70
70
|
if default_value
|
71
71
|
self[label] = default_value
|
72
|
-
elsif
|
72
|
+
elsif must
|
73
73
|
raise Mongous::Error, "must but unassigned field. : #{ label }"
|
74
74
|
elsif self.class.symbols[:strict]
|
75
75
|
self[label] = nil
|
@@ -78,11 +78,11 @@ module Mongous
|
|
78
78
|
|
79
79
|
case savemode
|
80
80
|
when :create
|
81
|
-
if
|
81
|
+
if ( create_value = getvalue_or_callproc( field[:create] ) )
|
82
82
|
self[label] = create_value
|
83
83
|
end
|
84
84
|
when :update
|
85
|
-
if
|
85
|
+
if ( update_value = getvalue_or_callproc( field[:update] ) )
|
86
86
|
self[label] = update_value
|
87
87
|
end
|
88
88
|
end
|
@@ -107,8 +107,8 @@ module Mongous
|
|
107
107
|
@doc.dup
|
108
108
|
end
|
109
109
|
|
110
|
-
def to_json
|
111
|
-
@doc
|
110
|
+
def to_json( **opts )
|
111
|
+
::JSON.generate( @doc, **opts )
|
112
112
|
end
|
113
113
|
|
114
114
|
def []( label )
|
@@ -144,10 +144,13 @@ module Mongous
|
|
144
144
|
end
|
145
145
|
|
146
146
|
field = self.class.fields[label]
|
147
|
-
|
147
|
+
if field.nil?
|
148
|
+
@doc[label] = value
|
149
|
+
return
|
150
|
+
end
|
148
151
|
|
149
152
|
types = []
|
150
|
-
if
|
153
|
+
if ( attrs = field[:_attrs] || [] )
|
151
154
|
attrs.each do |attr|
|
152
155
|
if attr.class == Class
|
153
156
|
types << attr
|
data/lib/mongous/extention.rb
CHANGED
@@ -5,18 +5,18 @@ module Mongous
|
|
5
5
|
if self.class_variable_defined?( :@@client )
|
6
6
|
self.class_variable_get( :@@client )
|
7
7
|
else
|
8
|
-
|
9
|
-
self.class_variable_set( :@@client,
|
8
|
+
new_client = Mongous.client
|
9
|
+
self.class_variable_set( :@@client, new_client )
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def client=(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
raise Mongous::Error, "type invalid. : #{
|
13
|
+
def client=( new_client )
|
14
|
+
if !new_client.is_a?( Mongo::Client )
|
15
|
+
m = /(.*?):(\d+)/.match( caller()[0] )
|
16
|
+
call_from = [ m[1], m[2] ].join(":")
|
17
|
+
raise Mongous::Error, "type invalid. : #{ new_client } at #{ call_from }"
|
18
18
|
end
|
19
|
-
self.class_variable_set( :@@client,
|
19
|
+
self.class_variable_set( :@@client, new_client )
|
20
20
|
end
|
21
21
|
|
22
22
|
def collection_name
|
@@ -28,8 +28,8 @@ module Mongous
|
|
28
28
|
self.class_variable_set( :@@collection_name, self.name )
|
29
29
|
end
|
30
30
|
|
31
|
-
def collection_name=(
|
32
|
-
self.class_variable_set( :@@collection_name,
|
31
|
+
def collection_name=( new_collection_name )
|
32
|
+
self.class_variable_set( :@@collection_name, new_collection_name )
|
33
33
|
if self.class_variable_defined?( :@@collection )
|
34
34
|
self.remove_class_variable( :@@collection )
|
35
35
|
end
|
@@ -38,29 +38,29 @@ module Mongous
|
|
38
38
|
def collection( temp_collection_name = nil )
|
39
39
|
if temp_collection_name.nil?
|
40
40
|
if self.class_variable_defined?( :@@collection )
|
41
|
-
if
|
42
|
-
return
|
41
|
+
if ( new_collection = self.class_variable_get( :@@collection ) )
|
42
|
+
return new_collection
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
new_collection_name = collection_name
|
46
46
|
else
|
47
|
-
|
47
|
+
new_collection_name = temp_collection_name
|
48
48
|
end
|
49
|
-
|
49
|
+
new_client = client
|
50
50
|
|
51
|
-
if
|
52
|
-
|
51
|
+
if new_client.database.collection_names.include?( new_collection_name )
|
52
|
+
new_collection = new_client[ new_collection_name ]
|
53
53
|
else
|
54
|
-
|
55
|
-
|
54
|
+
new_collection = new_client[ new_collection_name ]
|
55
|
+
new_collection.create
|
56
56
|
end
|
57
57
|
|
58
58
|
indexes.each do |keys, opts|
|
59
|
-
|
59
|
+
new_collection.indexes.create_one( keys, opts ) rescue nil
|
60
60
|
end
|
61
61
|
|
62
|
-
self.class_variable_set( :@@collection,
|
63
|
-
|
62
|
+
self.class_variable_set( :@@collection, new_collection ) if temp_collection_name.nil?
|
63
|
+
new_collection
|
64
64
|
end
|
65
65
|
|
66
66
|
def fields
|
@@ -114,7 +114,7 @@ module Mongous
|
|
114
114
|
call_from = [ m[1], m[2] ].join(":")
|
115
115
|
|
116
116
|
attrs.each do |attr|
|
117
|
-
if klass = attr.class
|
117
|
+
if ( klass = attr.class )
|
118
118
|
if ![Class, Range, Array, Regexp, Proc, Symbol].include?(klass)
|
119
119
|
raise Mongous::Error, "'field' arguments error. : #{ attr } on #{ symbol } at #{ call_from }"
|
120
120
|
end
|
data/lib/mongous/filter.rb
CHANGED
@@ -78,18 +78,18 @@ module Mongous
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def normalize( filter, conditions )
|
81
|
-
|
81
|
+
case filter
|
82
82
|
when Filter
|
83
83
|
filter.to_condition
|
84
84
|
when Symbol
|
85
|
-
case
|
85
|
+
case ( new_filter = filters[filter] )
|
86
86
|
when Filter
|
87
|
-
|
87
|
+
new_filter.to_condition
|
88
88
|
when Hash
|
89
|
-
|
89
|
+
new_filter
|
90
90
|
end
|
91
91
|
when NilClass
|
92
|
-
Filter.new( self ).where(
|
92
|
+
Filter.new( self ).where( conditions ).to_condition
|
93
93
|
else
|
94
94
|
caller_method = /`(.*?)'/.match( caller()[0] )[1]
|
95
95
|
raise Mongous::Error, "Invalid args for #{self}.#{ caller_method }. : #{filter}, #{conditions}"
|
@@ -125,17 +125,17 @@ module Mongous
|
|
125
125
|
hash[key] = {"$in"=>item}
|
126
126
|
|
127
127
|
when Range
|
128
|
-
|
129
|
-
|
128
|
+
begin_oper = "$gte"
|
129
|
+
end_oper = item.exclude_end? ? "$lt" : "$lte"
|
130
130
|
|
131
131
|
if item.begin && item.end
|
132
|
-
hash[key] = {
|
132
|
+
hash[key] = { begin_oper => item.begin, end_oper => item.end }
|
133
133
|
|
134
134
|
elsif !item.begin && item.end
|
135
|
-
hash[key] = {
|
135
|
+
hash[key] = { end_oper => item.end }
|
136
136
|
|
137
137
|
elsif item.begin && !item.end
|
138
|
-
hash[key] = {
|
138
|
+
hash[key] = { begin_oper => item.begin }
|
139
139
|
|
140
140
|
else
|
141
141
|
raise Mongous::Error, "invalid range. : #{ item }"
|
@@ -151,14 +151,14 @@ module Mongous
|
|
151
151
|
hash
|
152
152
|
end
|
153
153
|
|
154
|
-
def where( conditions )
|
154
|
+
def where( conditions = {} )
|
155
155
|
hash = build_condition( conditions )
|
156
156
|
w = self.dup
|
157
157
|
w.instance_variable_set( :@filter, @filter.merge( hash ) )
|
158
158
|
w
|
159
159
|
end
|
160
160
|
|
161
|
-
def not( conditions )
|
161
|
+
def not( conditions = {} )
|
162
162
|
hash = build_condition( conditions )
|
163
163
|
w = self.dup
|
164
164
|
w.instance_variable_set( :@filter, @filter.merge( {"$nor" => [hash]} ) )
|
@@ -169,49 +169,49 @@ module Mongous
|
|
169
169
|
@filter.dup
|
170
170
|
end
|
171
171
|
|
172
|
-
def option(
|
172
|
+
def option( new_option )
|
173
173
|
w = self.dup
|
174
|
-
w.instance_variable_set( :@option, @option.merge(
|
174
|
+
w.instance_variable_set( :@option, @option.merge( new_option ) )
|
175
175
|
w
|
176
176
|
end
|
177
177
|
|
178
178
|
def select( *keys, **hash )
|
179
179
|
if not keys.empty?
|
180
|
-
|
180
|
+
new_projection = Hash[ keys.zip( Array.new(keys.length, 1) ) ]
|
181
181
|
elsif not hash.empty?
|
182
|
-
|
182
|
+
new_projection = hash
|
183
183
|
else
|
184
|
-
|
184
|
+
new_projection = nil
|
185
185
|
end
|
186
186
|
w = self.dup
|
187
|
-
w.instance_variable_set( :@projection,
|
187
|
+
w.instance_variable_set( :@projection, new_projection )
|
188
188
|
w
|
189
189
|
end
|
190
190
|
|
191
191
|
def sort( *keys, **hash )
|
192
192
|
if not keys.empty?
|
193
|
-
|
193
|
+
new_sort = Hash[ keys.zip( Array.new( keys.length, 1 ) ) ]
|
194
194
|
elsif not hash.empty?
|
195
|
-
|
195
|
+
new_sort = hash
|
196
196
|
else
|
197
|
-
|
197
|
+
new_sort = nil
|
198
198
|
end
|
199
199
|
w = self.dup
|
200
|
-
w.instance_variable_set( :@sort,
|
200
|
+
w.instance_variable_set( :@sort, new_sort )
|
201
201
|
w
|
202
202
|
end
|
203
203
|
|
204
204
|
def []( nth_or_range, len = nil )
|
205
205
|
case nth_or_range
|
206
206
|
when Integer
|
207
|
-
|
207
|
+
new_skip = nth_or_range
|
208
208
|
|
209
209
|
if len.is_a?(NilClass)
|
210
|
-
|
210
|
+
new_limit = 1
|
211
211
|
elsif len.is_a?(Integer) && len == 0
|
212
|
-
|
212
|
+
new_limit = nil
|
213
213
|
elsif len.is_a?(Integer) && len > 0
|
214
|
-
|
214
|
+
new_limit = len
|
215
215
|
else
|
216
216
|
raise Mongous::Error, "invalid len. : #{ len }"
|
217
217
|
end
|
@@ -224,8 +224,8 @@ module Mongous
|
|
224
224
|
raise Mongous::Error, "invalid range. : #{ nth_or_range }" unless to.is_a? Integer
|
225
225
|
|
226
226
|
to -= 1 if nth_or_range.exclude_end?
|
227
|
-
|
228
|
-
|
227
|
+
new_skip = from
|
228
|
+
new_limit = to - from + 1
|
229
229
|
|
230
230
|
else
|
231
231
|
raise Mongous::Error, "invalid class. : #{ nth_or_range }"
|
@@ -233,16 +233,16 @@ module Mongous
|
|
233
233
|
end
|
234
234
|
|
235
235
|
w = self.dup
|
236
|
-
w.instance_variable_set( :@skip,
|
237
|
-
w.instance_variable_set( :@limit,
|
236
|
+
w.instance_variable_set( :@skip, new_skip )
|
237
|
+
w.instance_variable_set( :@limit, new_limit )
|
238
238
|
w
|
239
239
|
end
|
240
240
|
|
241
241
|
def exec_query
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
found = @klass.collection( @collection_name ).find(
|
242
|
+
new_filter = @filter
|
243
|
+
new_option = @option.dup
|
244
|
+
new_option[:projection] = @projection if @projection
|
245
|
+
found = @klass.collection( @collection_name ).find( new_filter, new_option )
|
246
246
|
found = found.sort( @sort ) if @sort
|
247
247
|
found = found.skip( @skip ) if @skip
|
248
248
|
found = found.limit( @limit ) if @limit
|
@@ -253,44 +253,44 @@ module Mongous
|
|
253
253
|
found = @klass.collection.find( @filter )
|
254
254
|
found = found.skip( @skip ) if @skip
|
255
255
|
found = found.limit( @limit ) if @limit
|
256
|
-
|
256
|
+
new_count = found.count_documents
|
257
257
|
if @skip
|
258
|
-
if @skip >
|
258
|
+
if @skip > new_count
|
259
259
|
0
|
260
260
|
elsif @limit
|
261
|
-
[
|
261
|
+
[new_count - @skip, @limit].min
|
262
262
|
else
|
263
|
-
|
263
|
+
new_count - @skip
|
264
264
|
end
|
265
265
|
else
|
266
266
|
if @limit
|
267
|
-
[
|
267
|
+
[new_count, @limit].min
|
268
268
|
else
|
269
|
-
|
269
|
+
new_count
|
270
270
|
end
|
271
271
|
end
|
272
272
|
end
|
273
273
|
|
274
274
|
def first
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
found = @klass.collection( @collection_name ).find(
|
279
|
-
|
280
|
-
doc = found.sort(
|
275
|
+
new_filter = @filter
|
276
|
+
new_option = @option.dup
|
277
|
+
new_option[:projection] = @projection if @projection
|
278
|
+
found = @klass.collection( @collection_name ).find( new_filter, new_option )
|
279
|
+
new_order = @sort || { _id: 1 }
|
280
|
+
doc = found.sort( new_order ).first
|
281
281
|
@klass.new( **doc ) if doc
|
282
282
|
end
|
283
283
|
|
284
284
|
def last
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
found = @klass.collection( @collection_name ).find(
|
289
|
-
|
285
|
+
new_filter = @filter
|
286
|
+
new_option = @option.dup
|
287
|
+
new_option[:projection] = @projection if @projection
|
288
|
+
found = @klass.collection( @collection_name ).find( new_filter, new_option )
|
289
|
+
new_order = {}
|
290
290
|
( @sort || {_id: 1} ).each do |k,v|
|
291
|
-
|
291
|
+
new_order[k] = - v
|
292
292
|
end
|
293
|
-
doc = found.sort(
|
293
|
+
doc = found.sort( new_order ).first
|
294
294
|
@klass.new( **doc ) if doc
|
295
295
|
end
|
296
296
|
|
data/lib/mongous/version.rb
CHANGED
data/mongous.gemspec
CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "mongo"
|
23
|
+
spec.add_runtime_dependency "mongo"
|
24
24
|
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
27
|
end
|
data/sample/save_detail_3.rb
CHANGED
@@ -7,7 +7,7 @@ class Book
|
|
7
7
|
field :title, :must
|
8
8
|
field :author
|
9
9
|
field :publisher
|
10
|
-
field :style, %w[hardcover
|
10
|
+
field :style, %w[hardcover softcover paperback]
|
11
11
|
field :size, /[AB]\d/
|
12
12
|
field :price, Integer, (0..1_000_000)
|
13
13
|
field :page, Integer, proc{ page > 0 }
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongous
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arimay
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
description: " Yet another mongo wrapper library. "
|
56
56
|
email:
|
57
57
|
- arima.yasuhiro@gmail.com
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".rubocop.yml"
|
64
65
|
- ".travis.yml"
|
65
66
|
- Gemfile
|
66
67
|
- README.adoc
|
@@ -135,7 +136,7 @@ homepage: https://github.com/arimay/mongous
|
|
135
136
|
licenses:
|
136
137
|
- MIT
|
137
138
|
metadata: {}
|
138
|
-
post_install_message:
|
139
|
+
post_install_message:
|
139
140
|
rdoc_options: []
|
140
141
|
require_paths:
|
141
142
|
- lib
|
@@ -150,8 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
151
|
- !ruby/object:Gem::Version
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
154
|
-
signing_key:
|
154
|
+
rubygems_version: 3.2.3
|
155
|
+
signing_key:
|
155
156
|
specification_version: 4
|
156
157
|
summary: Mongo wrapper library.
|
157
158
|
test_files: []
|