mongocore 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/mongocore.rb +1 -1
- data/lib/mongocore/document.rb +12 -4
- data/mongocore.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 101270d2604389fccdfd5cb57406447a7a722ee6
|
4
|
+
data.tar.gz: 94e67537e7c525525bde6af3afeb63d1160d994d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 213d43d5682528b73b2088fb5e65fdba442b8e78f768cb40875aa5778ed4d3cefbbe6e7ddad5b91319de6250255b6a051a443e54b0a7582f0a5e29763d9c4195
|
7
|
+
data.tar.gz: 5af984bb234f941208cbbba636ff6183bc07f1d3e9e30d41162078434a7798b60bf3026dd4d0d87685ef7d3d3d44bb4558c9958e600637989a0b7e6048e7f1e6
|
data/CHANGELOG.md
CHANGED
data/lib/mongocore.rb
CHANGED
data/lib/mongocore/document.rb
CHANGED
@@ -50,8 +50,11 @@ module Mongocore
|
|
50
50
|
#
|
51
51
|
def initialize(a = {})
|
52
52
|
|
53
|
-
# Store attributes.
|
54
|
-
self.attributes = self.class.schema.defaults.merge(a)
|
53
|
+
# Store attributes.
|
54
|
+
self.attributes = @_id ? a : self.class.schema.defaults.merge(a)
|
55
|
+
|
56
|
+
# Storing original state for dirty tracking.
|
57
|
+
@original = self.attributes
|
55
58
|
|
56
59
|
# The _id is a BSON object, create new unless it exists
|
57
60
|
@_id ? @persisted = true : @_id = BSON::ObjectId.new
|
@@ -87,12 +90,12 @@ module Mongocore
|
|
87
90
|
|
88
91
|
# Run filters before and after accessing the db
|
89
92
|
def filter(cmd, persisted = true, &block)
|
90
|
-
run(:before, cmd); yield.tap{@persisted = persisted; run(:after, cmd)}
|
93
|
+
run(:before, cmd); yield.tap{@persisted = persisted; run(:after, cmd); reset!}
|
91
94
|
end
|
92
95
|
|
93
96
|
# Reload the document from db and update attributes
|
94
97
|
def reload
|
95
|
-
one.first.tap{|m| self.attributes = m.attributes;
|
98
|
+
one.first.tap{|m| self.attributes = m.attributes; reset!}
|
96
99
|
end
|
97
100
|
|
98
101
|
# Set the timestamps if enabled
|
@@ -100,6 +103,11 @@ module Mongocore
|
|
100
103
|
t = Time.now.utc; @updated_at = t; @created_at = t if unsaved?
|
101
104
|
end
|
102
105
|
|
106
|
+
# Reset internals
|
107
|
+
def reset!
|
108
|
+
@original = self.attributes; @changes.clear; @errors.clear
|
109
|
+
end
|
110
|
+
|
103
111
|
|
104
112
|
# # # # # # # # # # # # # # # #
|
105
113
|
# Attribute methods
|
data/mongocore.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mongocore'
|
3
|
-
s.version = '0.4.
|
3
|
+
s.version = '0.4.4'
|
4
4
|
s.date = '2018-01-19'
|
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."
|