mongocore 0.1.5.4 → 0.1.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 528cba77e5787960a365aa15629a703e41fcedd3
4
- data.tar.gz: 774cb561e0ce794c80a3ff3a03e0cc00c8ec767c
3
+ metadata.gz: e84e4c0a90381ed50bdc7912bded6cec7659fe48
4
+ data.tar.gz: a8dc0e269b5f2795a4d24cdc86f821e2e61d8076
5
5
  SHA512:
6
- metadata.gz: 4648a17cbc9670bef907be425fa17a3c50a924cefedf7f35e08364130c0f409c3f130abc39d896a8dfc4091cd3801b75b67e537bf745079888852a15585e2e91
7
- data.tar.gz: d3a1921104bbbc4f26ab79bbe789105fb878e285e1dbf13cdfcd5a0130320d11ad2dde5b345ae81e0d81abbe1f71cf275cba2543163dfb00206ac11f70c6c251
6
+ metadata.gz: a6fa7f82aa0107dbbb0947fe3ca7954980e3ae752c90b6ff626f3e90de96c1a569969578fbe5cbdbc1ed467ef7cc39fb4f66dafd1e289ade151122dbea1f3c64
7
+ data.tar.gz: 346c9981648cbff471c3cfe3a7b9ef028c21afbb8de698e317543e216ba39f3e144a1ac746b998c26bf4f5928aca034bcb74d14df1ef5860a97f17222aa44c9d
@@ -14,7 +14,7 @@ module Mongocore
14
14
  # The Model class, accessible from Model or m.class, holds the data
15
15
  # for your models like the schema and the keys.
16
16
  #
17
- # The model instance, m, lets you do operations on a single model
17
+ # The model instance, m, lets you do operations on a model
18
18
  # like m.save, m.update, m.delete
19
19
  #
20
20
 
@@ -72,21 +72,17 @@ module Mongocore
72
72
 
73
73
  # Save attributes to db
74
74
  def save(o = {})
75
- # Send :validate => true to validate
76
- return false unless valid? if o[:validate]
77
-
78
- # Create a new query
79
- filter(:save){mq(self.class, {:_id => @_id}).update(attributes).ok?}
75
+ persist(:save, o)
80
76
  end
81
77
 
82
78
  # Update document in db
83
- def update(a = {})
84
- self.attributes = a; filter(:update){single.update(a).ok?}
79
+ def update(a = {}, o = {})
80
+ self.attributes = a; persist(:update, o)
85
81
  end
86
82
 
87
83
  # Delete a document in db
88
84
  def delete
89
- filter(:delete, false){single.delete}
85
+ filter(:delete, false){one.delete}
90
86
  end
91
87
 
92
88
  # Run filters before and after accessing the db
@@ -96,7 +92,7 @@ module Mongocore
96
92
 
97
93
  # Reload the document from db and update attributes
98
94
  def reload
99
- single.first.tap{|m| attributes = m.attributes}
95
+ one.first.tap{|m| attributes = m.attributes}
100
96
  end
101
97
 
102
98
  # Set the timestamps if enabled
@@ -160,8 +156,8 @@ module Mongocore
160
156
  Mongocore::Query.new(m, q, o, {:source => self}.merge(s))
161
157
  end
162
158
 
163
- # Short cut for simple query with cache buster
164
- def single(s = {:cache => false})
159
+ # Short cut for query needing only id
160
+ def one(s = {})
165
161
  mq(self.class, {:_id => @_id}, {}, s)
166
162
  end
167
163
 
@@ -230,6 +226,17 @@ module Mongocore
230
226
  a.delete(:_id); {:id => id}.merge(a)
231
227
  end
232
228
 
229
+ private
230
+
231
+ # Persist for save and update
232
+ def persist(type, o)
233
+ # Send :validate => true to validate
234
+ return false unless valid? if o[:validate]
235
+
236
+ # Create a new query
237
+ filter(type){one.update(attributes).ok?}
238
+ end
239
+
233
240
  end
234
241
 
235
242
 
@@ -34,7 +34,7 @@ module Mongocore
34
34
 
35
35
  # Find. Returns a Mongocore::Query
36
36
  def find(q = {}, o = {}, s = {})
37
- self.class.new(@model, @query.merge(normalize(q)), @options.merge(o), @store.merge(s))
37
+ self.class.new(@model, @query.merge(q.is_a?(Hash) ? q : {:_id => q}), @options.merge(o), @store.merge(s))
38
38
  end
39
39
 
40
40
  # Normalize query
@@ -53,7 +53,7 @@ module Mongocore
53
53
  elsif type == :integer then val.to_i
54
54
  elsif type == :float then val.to_f
55
55
  elsif type == :boolean then !!val
56
- elsif type == :object_id && val.is_a?(String)
56
+ elsif type == :object_id && !val.is_a?(BSON::ObjectId)
57
57
  BSON::ObjectId.from_string(val) rescue nil
58
58
  else
59
59
  val
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.1.5.4'
10
+ VERSION = '0.1.5.5'
11
11
 
12
12
  # # # # # #
13
13
  # Mongocore Ruby Database Driver.
data/mongocore.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mongocore'
3
- s.version = '0.1.5.4'
4
- s.date = '2017-10-18'
3
+ s.version = '0.1.5.5'
4
+ s.date = '2017-10-20'
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.1.5.4
4
+ version: 0.1.5.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: 2017-10-18 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo