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 +4 -4
- data/lib/mongocore/document.rb +19 -12
- data/lib/mongocore/query.rb +1 -1
- data/lib/mongocore/schema.rb +1 -1
- data/lib/mongocore.rb +1 -1
- 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: e84e4c0a90381ed50bdc7912bded6cec7659fe48
|
4
|
+
data.tar.gz: a8dc0e269b5f2795a4d24cdc86f821e2e61d8076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fa7f82aa0107dbbb0947fe3ca7954980e3ae752c90b6ff626f3e90de96c1a569969578fbe5cbdbc1ed467ef7cc39fb4f66dafd1e289ade151122dbea1f3c64
|
7
|
+
data.tar.gz: 346c9981648cbff471c3cfe3a7b9ef028c21afbb8de698e317543e216ba39f3e144a1ac746b998c26bf4f5928aca034bcb74d14df1ef5860a97f17222aa44c9d
|
data/lib/mongocore/document.rb
CHANGED
@@ -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
|
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
|
-
|
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;
|
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){
|
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
|
-
|
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
|
164
|
-
def
|
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
|
|
data/lib/mongocore/query.rb
CHANGED
@@ -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(
|
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
|
data/lib/mongocore/schema.rb
CHANGED
@@ -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?(
|
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
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
|
-
s.date = '2017-10-
|
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
|
+
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-
|
11
|
+
date: 2017-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|