mongocore 0.3.2 → 0.4.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -1
- data/lib/mongocore.rb +2 -2
- data/lib/mongocore/document.rb +29 -3
- data/lib/mongocore/query.rb +29 -6
- data/mongocore.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6530290c756f80c471d9c5565e7885fcf80a2c33
|
4
|
+
data.tar.gz: ba0ea77310386d919069e77552aee4620223e6ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecfc84ad83cf9f41669613c5925ff13aa632ace888bb4b6351d352a221a885b8114363f08cdec8449312330822d6947f2be51682190b9acfe134814d0f00d1ee
|
7
|
+
data.tar.gz: 70327cb292727616e66d15c842184746be4bd8e06fd362543d358dbfec4c593d963a31a89c7a6c16c624f4e4b02d540cd50ce9263fba3a4c54382a89168e92aa
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
**Version 0.4.0** - *2017-12-01*
|
2
|
+
|
3
|
+
- Added each_with_index, each_with_object and map
|
4
|
+
- Added id = method
|
5
|
+
- Refactored cursor, faster finds
|
6
|
+
- Added paginate to model class methods
|
7
|
+
|
8
|
+
|
1
9
|
**Version 0.3.2** - *2017-11-25*
|
2
10
|
|
3
11
|
- Alias for insert is create
|
data/README.md
CHANGED
data/lib/mongocore.rb
CHANGED
@@ -7,7 +7,7 @@ require 'mongo'
|
|
7
7
|
require 'request_store'
|
8
8
|
|
9
9
|
module Mongocore
|
10
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.4.0'
|
11
11
|
|
12
12
|
# # # # # #
|
13
13
|
# Mongocore Ruby Database Driver.
|
@@ -31,7 +31,7 @@ module Mongocore
|
|
31
31
|
@timestamps = true
|
32
32
|
|
33
33
|
# Default sorting, last will be opposite. Should be indexed.
|
34
|
-
@sort = {
|
34
|
+
@sort = {}
|
35
35
|
|
36
36
|
# Pagination results per page
|
37
37
|
@per_page = 20
|
data/lib/mongocore/document.rb
CHANGED
@@ -221,6 +221,11 @@ module Mongocore
|
|
221
221
|
@_id ? @_id.to_s : nil
|
222
222
|
end
|
223
223
|
|
224
|
+
# Assign id
|
225
|
+
def id=(val)
|
226
|
+
@_id = val.is_a?(BSON::ObjectId) ? val : BSON::ObjectId.from_string(val)
|
227
|
+
end
|
228
|
+
|
224
229
|
# Print info about the instance
|
225
230
|
def inspect
|
226
231
|
"#<#{self.class} #{attributes.sort.map{|r| %{#{r[0]}: #{r[1].inspect}}}.join(', ')}>"
|
@@ -277,6 +282,11 @@ module Mongocore
|
|
277
282
|
find(*args).all
|
278
283
|
end
|
279
284
|
|
285
|
+
# Paginate
|
286
|
+
def paginate(*args)
|
287
|
+
find({}).paginate(*args)
|
288
|
+
end
|
289
|
+
|
280
290
|
# Sort
|
281
291
|
def sort(o = {})
|
282
292
|
find({}, {}, :sort => o)
|
@@ -292,10 +302,11 @@ module Mongocore
|
|
292
302
|
find({}, {}, :skip => n)
|
293
303
|
end
|
294
304
|
|
295
|
-
#
|
296
|
-
def
|
297
|
-
find({}, {}, :
|
305
|
+
# Projection
|
306
|
+
def projection(o = {})
|
307
|
+
find({}, {}, :projection => o)
|
298
308
|
end
|
309
|
+
alias_method :fields, :projection
|
299
310
|
|
300
311
|
# Insert
|
301
312
|
def insert(a = {}, o = {})
|
@@ -308,6 +319,21 @@ module Mongocore
|
|
308
319
|
find.each{|r| yield(r)}
|
309
320
|
end
|
310
321
|
|
322
|
+
# Each with index
|
323
|
+
def each_with_index(&block)
|
324
|
+
find.each_with_index{|r, n| yield(r, n)}
|
325
|
+
end
|
326
|
+
|
327
|
+
# Each with object
|
328
|
+
def each_with_object(obj, &block)
|
329
|
+
find.each_with_object(obj){|r, o| yield(r, o)}
|
330
|
+
end
|
331
|
+
|
332
|
+
# Map
|
333
|
+
def map(&block)
|
334
|
+
find.map{|r| yield(r)}
|
335
|
+
end
|
336
|
+
|
311
337
|
|
312
338
|
# # # # # # # # #
|
313
339
|
# After, before and validation filters
|
data/lib/mongocore/query.rb
CHANGED
@@ -25,7 +25,7 @@ module Mongocore
|
|
25
25
|
@collection = Mongocore.db[@colname]
|
26
26
|
|
27
27
|
# Storing query and options
|
28
|
-
s[:
|
28
|
+
s[:chain] ||= []; s[:source] ||= nil; s[:sort] ||= Mongocore.sort; s[:projection] ||= {}; s[:skip] ||= 0; s[:limit] ||= 0
|
29
29
|
@query, @options, @store = @model.schema.ids(hashify(q)), o, s
|
30
30
|
|
31
31
|
# Set up cache
|
@@ -45,7 +45,12 @@ module Mongocore
|
|
45
45
|
|
46
46
|
# Cursor
|
47
47
|
def cursor
|
48
|
-
@collection.find(@query, @options)
|
48
|
+
c = @collection.find(@query, @options)
|
49
|
+
c = c.sort(@store[:sort]) if @store[:sort].any?
|
50
|
+
c = c.projection(@store[:projection]) if @store[:projection].any?
|
51
|
+
c = c.skip(@store[:skip]) if @store[:skip] > 0
|
52
|
+
c = c.limit(@store[:limit]) if @store[:limit] > 0
|
53
|
+
c
|
49
54
|
end
|
50
55
|
|
51
56
|
# Insert
|
@@ -85,8 +90,10 @@ module Mongocore
|
|
85
90
|
end
|
86
91
|
|
87
92
|
# Return last document
|
93
|
+
# Uses the opposite of the Mongocore.sort setting
|
88
94
|
def last(*args)
|
89
|
-
|
95
|
+
a = Mongocore.sort.any? ? Mongocore.sort.dup : {:_id => 1}
|
96
|
+
sort(a.each{|k, v| a[k] = v * -1}).limit(1).first(*args)
|
90
97
|
end
|
91
98
|
|
92
99
|
# Return all documents
|
@@ -133,6 +140,21 @@ module Mongocore
|
|
133
140
|
cursor.each{|r| yield(modelize(r))}
|
134
141
|
end
|
135
142
|
|
143
|
+
# Each with index
|
144
|
+
def each_with_index(&block)
|
145
|
+
cursor.each_with_index{|r, n| yield(modelize(r), n)}
|
146
|
+
end
|
147
|
+
|
148
|
+
# Each with object
|
149
|
+
def each_with_object(obj, &block)
|
150
|
+
cursor.each_with_object(obj){|r, o| yield(modelize(r), o)}
|
151
|
+
end
|
152
|
+
|
153
|
+
# Map
|
154
|
+
def map(&block)
|
155
|
+
cursor.map{|r| yield(modelize(r))}
|
156
|
+
end
|
157
|
+
|
136
158
|
# Sort
|
137
159
|
def sort(o = {})
|
138
160
|
find(@query, @options, @store.tap{(store[:sort] ||= {}).merge!(o)})
|
@@ -148,10 +170,11 @@ module Mongocore
|
|
148
170
|
find(@query, @options, @store.tap{store[:skip] = n})
|
149
171
|
end
|
150
172
|
|
151
|
-
#
|
152
|
-
def
|
153
|
-
find(@query, @options, @store.tap{store[:
|
173
|
+
# Projection
|
174
|
+
def projection(o = {})
|
175
|
+
find(@query, @options, @store.tap{store[:projection].merge!(o)})
|
154
176
|
end
|
177
|
+
alias_method :fields, :projection
|
155
178
|
|
156
179
|
# JSON format
|
157
180
|
def as_json(o = {})
|
data/mongocore.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mongocore'
|
3
|
-
s.version = '0.
|
4
|
-
s.date = '2017-
|
3
|
+
s.version = '0.4.0'
|
4
|
+
s.date = '2017-12-01'
|
5
5
|
s.summary = "MongoDB ORM implementation on top of the Ruby MongoDB driver"
|
6
6
|
s.description = "Does validations, associations, scopes, filters, pagination, counter cache, request cache, and nested queries. Using a YAML schema file, which supports default values, data types, and security levels for each key."
|
7
7
|
s.authors = ['Fugroup Limited']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongocore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fugroup Limited
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|