mongocore 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 101270d2604389fccdfd5cb57406447a7a722ee6
4
- data.tar.gz: 94e67537e7c525525bde6af3afeb63d1160d994d
3
+ metadata.gz: 2b7497f2ffc863157d942ced1f326b41a595ab1f
4
+ data.tar.gz: f65ce1925bc082ffa01b603f8975752c40960b8e
5
5
  SHA512:
6
- metadata.gz: 213d43d5682528b73b2088fb5e65fdba442b8e78f768cb40875aa5778ed4d3cefbbe6e7ddad5b91319de6250255b6a051a443e54b0a7582f0a5e29763d9c4195
7
- data.tar.gz: 5af984bb234f941208cbbba636ff6183bc07f1d3e9e30d41162078434a7798b60bf3026dd4d0d87685ef7d3d3d44bb4558c9958e600637989a0b7e6048e7f1e6
6
+ metadata.gz: d8728af7535106eb8865794093c8cca1b44d20276864267760622b03a183a818b80d63fdd92fa37b53d344b2ff21fd4e1d62aeeebe87a7d6bcfaa043622bd80c
7
+ data.tar.gz: 49ba47e50f24a96ef3d3e4441145661e93c5651787fd02d9b4a4a4714a070ad2e5945815d36d9ee802a06a7a9868c6a613a5f45b0d2c025fa9e954a3075df5d8
@@ -1,7 +1,15 @@
1
+ **Version 0.4.5** - *2018-01-23*
2
+
3
+ - Fixed memory bug with Mongocore.sort option
4
+ - Removed unused option
5
+ - Optimized cursor query
6
+
7
+
1
8
  **Version 0.4.4** - *2018-01-19*
2
9
 
3
10
  - Fixed dirty tracking clearing after save
4
11
 
12
+
5
13
  **Version 0.4.3** - *2018-01-19*
6
14
 
7
15
  - Reset model properly when doing a reload
data/README.md CHANGED
@@ -134,13 +134,13 @@ Model.find(:duration => 50).each{|m| puts m}
134
134
  m = Model.find(:house => {:$ne => nil, :$eq => 'Nice'}).last
135
135
 
136
136
  # Sorting, use -1 for descending, 1 for ascending
137
- m = Model.find({:duration => {:$gt => 40}}, {}, :sort => {:duration => -1}).all
137
+ m = Model.find({:duration => {:$gt => 40}}, :sort => {:duration => -1}).all
138
138
  m = p.models.find(:duration => 10).sort(:duration => -1).first
139
139
 
140
140
  # Limit, pass as third option to find or chain, up to you
141
141
  p = Parent.find.sort(:duration => 1).limit(5).all
142
142
  p = Parent.limit(1).last
143
- m = p.models.find({}, {}, :sort => {:goal => 1}, :limit => 1).first
143
+ m = p.models.find({}, :sort => {:goal => 1}, :limit => 1).first
144
144
  m = Model.sort(:goal => 1, :duration => -1).limit(10).all
145
145
 
146
146
  # First
@@ -7,7 +7,7 @@ require 'mongo'
7
7
  require 'request_store'
8
8
 
9
9
  module Mongocore
10
- VERSION = '0.4.4'
10
+ VERSION = '0.4.5'
11
11
 
12
12
  # # # # # #
13
13
  # Mongocore Ruby Database Driver.
@@ -161,13 +161,13 @@ module Mongocore
161
161
  alias_method :new_record?, :unsaved?
162
162
 
163
163
  # Short cut for setting up a Mongocore::Query object
164
- def mq(m, q = {}, o = {}, s = {})
165
- Mongocore::Query.new(m, q, o, {:source => self}.merge(s))
164
+ def mq(m, q = {}, o = {})
165
+ Mongocore::Query.new(m, q, {:source => self}.merge(o))
166
166
  end
167
167
 
168
168
  # Short cut for query needing only id
169
- def one(s = {})
170
- mq(self.class, {:_id => @_id}, {}, s)
169
+ def one(o = {})
170
+ mq(self.class, {:_id => @_id}, o)
171
171
  end
172
172
 
173
173
 
@@ -297,22 +297,22 @@ module Mongocore
297
297
 
298
298
  # Sort
299
299
  def sort(o = {})
300
- find({}, {}, :sort => o)
300
+ find({}, :sort => o)
301
301
  end
302
302
 
303
303
  # Limit
304
304
  def limit(n = 1)
305
- find({}, {}, :limit => n)
305
+ find({}, :limit => n)
306
306
  end
307
307
 
308
308
  # Skip
309
309
  def skip(n = 0)
310
- find({}, {}, :skip => n)
310
+ find({}, :skip => n)
311
311
  end
312
312
 
313
313
  # Projection
314
314
  def projection(o = {})
315
- find({}, {}, :projection => o)
315
+ find({}, :projection => o)
316
316
  end
317
317
  alias_method :fields, :projection
318
318
 
@@ -10,12 +10,12 @@ module Mongocore
10
10
  # it's only the parameters that change.
11
11
  #
12
12
 
13
- attr_accessor :model, :collection, :colname, :query, :options, :store, :cache
13
+ attr_accessor :model, :collection, :colname, :query, :options, :cache
14
14
 
15
15
  # Mongocore query initializer
16
- def initialize(m, q = {}, o = {}, s = {})
16
+ def initialize(m, q = {}, o = {})
17
17
 
18
- # Storing model class. The instance can be found in store[:source]
18
+ # Storing model class. The instance can be found in options[:source]
19
19
  @model = m
20
20
 
21
21
  # The model name is singular, the collection name is plural
@@ -24,17 +24,24 @@ module Mongocore
24
24
  # Storing the Mongo::Collection object
25
25
  @collection = Mongocore.db[@colname]
26
26
 
27
+ # Default options
28
+ o[:source] ||= nil
29
+ o[:chain] ||= []
30
+ o[:skip] ||= 0
31
+ o[:limit] ||= 0
32
+ o[:sort] ||= Mongocore.sort.dup
33
+ o[:projection] ||= {}
34
+
27
35
  # Storing query and options
28
- s[:chain] ||= []; s[:source] ||= nil; s[:sort] ||= Mongocore.sort; s[:projection] ||= {}; s[:skip] ||= 0; s[:limit] ||= 0
29
- @query, @options, @store = @model.schema.ids(hashify(q)), o, s
36
+ @query, @options = @model.schema.ids(hashify(q)), o
30
37
 
31
38
  # Set up cache
32
39
  @cache = Mongocore::Cache.new(self)
33
40
  end
34
41
 
35
42
  # Find. Returns a Mongocore::Query
36
- def find(q = {}, o = {}, s = {})
37
- self.class.new(@model, @query.merge(hashify(q)), @options.merge(o), @store.merge(s))
43
+ def find(q = {}, o = {})
44
+ self.class.new(@model, @query.merge(hashify(q)), @options.merge(o))
38
45
  end
39
46
  alias_method :where, :find
40
47
 
@@ -45,12 +52,16 @@ module Mongocore
45
52
 
46
53
  # Cursor
47
54
  def cursor
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
55
+ o = @options.dup
56
+
57
+ # Remove blank options
58
+ o.delete(:skip) if o[:skip] < 1
59
+ o.delete(:limit) if o[:limit] < 1
60
+ o.delete(:sort) if o[:sort].empty?
61
+ o.delete(:projection) if o[:projection].empty?
62
+
63
+ # Return view
64
+ @collection.find(@query, o)
54
65
  end
55
66
 
56
67
  # Insert
@@ -80,7 +91,7 @@ module Mongocore
80
91
  end
81
92
 
82
93
  # Check if there's a corresponding counter for this count
83
- def counter(s = @store[:source], c = @store[:chain])
94
+ def counter(s = @options[:source], c = @options[:chain])
84
95
  s.send(%{#{@colname}#{c.present? ? "_#{c.join('_')}" : ''}_count}) rescue nil
85
96
  end
86
97
 
@@ -107,16 +118,18 @@ module Mongocore
107
118
  total = fetch(:count)
108
119
 
109
120
  # Set page, defaults to 1
110
- o[:page] = o[:page].to_i; o[:page] = 1 if o[:page] < 1
121
+ o[:page] = o[:page].to_i
122
+ o[:page] = 1 if o[:page] < 1
111
123
 
112
124
  # Set results per page, defaults to 20 in Mongocore.per_page setting
113
- o[:per_page] = o[:per_page].to_i; o[:per_page] = Mongocore.per_page if o[:per_page] < 1
125
+ o[:per_page] = o[:per_page].to_i
126
+ o[:per_page] = Mongocore.per_page if o[:per_page] < 1
114
127
 
115
128
  # Skip results
116
- @store[:skip] = o[:per_page] * (o[:page] - 1)
129
+ @options[:skip] = o[:per_page] * (o[:page] - 1)
117
130
 
118
131
  # Apply limit
119
- @store[:limit] = o[:per_page]
132
+ @options[:limit] = o[:per_page]
120
133
 
121
134
  # Fetch the result as array
122
135
  all.tap{|r| r.total = total}
@@ -157,22 +170,22 @@ module Mongocore
157
170
 
158
171
  # Sort
159
172
  def sort(o = {})
160
- find(@query, @options, @store.tap{(store[:sort] ||= {}).merge!(o)})
173
+ find(@query, @options.tap{(@options[:sort] ||= {}).merge!(o)})
161
174
  end
162
175
 
163
176
  # Limit
164
177
  def limit(n = 1)
165
- find(@query, @options, @store.tap{store[:limit] = n})
178
+ find(@query, @options.tap{@options[:limit] = n})
166
179
  end
167
180
 
168
181
  # Skip
169
182
  def skip(n = 0)
170
- find(@query, @options, @store.tap{store[:skip] = n})
183
+ find(@query, @options.tap{@options[:skip] = n})
171
184
  end
172
185
 
173
186
  # Projection
174
187
  def projection(o = {})
175
- find(@query, @options, @store.tap{store[:projection].merge!(o)})
188
+ find(@query, @options.tap{@options[:projection].merge!(o)})
176
189
  end
177
190
  alias_method :fields, :projection
178
191
 
@@ -183,12 +196,12 @@ module Mongocore
183
196
 
184
197
  # Cache key
185
198
  def key
186
- @key ||= "#{@model}#{@query.sort}#{@options.sort}#{@store.values}"
199
+ @key ||= "#{@model}#{@query.sort}#{@options.values}"
187
200
  end
188
201
 
189
202
  # Call and return the scope if it exists
190
203
  def method_missing(name, *arguments, &block)
191
- return @model.send(name, @query, @options, @store.tap{|r| r[:chain] << name}) if @model.schema.scopes.has_key?(name)
204
+ return @model.send(name, @query, @options.tap{|r| r[:chain] << name}) if @model.schema.scopes.has_key?(name)
192
205
  super
193
206
  end
194
207
 
@@ -126,7 +126,7 @@ module Mongocore
126
126
  def many(key)
127
127
  t = %Q{
128
128
  def #{key}
129
- mq(#{key.to_s.singularize.capitalize}, {:#{@klass.to_s.downcase}_id => @_id}, {}, :source => self)
129
+ mq(#{key.to_s.singularize.capitalize}, {:#{@klass.to_s.downcase}_id => @_id}, :source => self)
130
130
  end
131
131
  }
132
132
  @klass.class_eval t
@@ -148,8 +148,8 @@ module Mongocore
148
148
  # Define the scope method so we can call it
149
149
  j = pm.any? ? %{#{pm.join(', ')},} : ''
150
150
  t = %Q{
151
- def #{key}(#{j} q = {}, o = {}, s = {})
152
- mq(self, q.merge(#{d}), o, {:scope => [:#{key}]}.merge(s))
151
+ def #{key}(#{j} q = {}, o = {})
152
+ mq(self, q.merge(#{d}), {:scope => [:#{key}]}.merge(o))
153
153
  end
154
154
  }
155
155
  @klass.instance_eval t
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mongocore'
3
- s.version = '0.4.4'
4
- s.date = '2018-01-19'
3
+ s.version = '0.4.5'
4
+ s.date = '2018-01-23'
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.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fugroup Limited
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-19 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo