mongomodel 0.2.17 → 0.2.18
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.
@@ -18,7 +18,6 @@ module MongoModel
|
|
18
18
|
|
19
19
|
def load!(hash)
|
20
20
|
from_mongo!(hash)
|
21
|
-
changed.clear
|
22
21
|
end
|
23
22
|
|
24
23
|
def from_mongo!(hash)
|
@@ -26,7 +25,7 @@ module MongoModel
|
|
26
25
|
property = properties_as[k.to_s]
|
27
26
|
|
28
27
|
if property
|
29
|
-
child =
|
28
|
+
child = store(property.name, property.from_mongo(v))
|
30
29
|
child.parent_document = instance if child.respond_to?(:parent_document=)
|
31
30
|
else
|
32
31
|
self[k.to_sym] = v
|
@@ -10,14 +10,37 @@ module MongoModel
|
|
10
10
|
after_save { changed_attributes.clear }
|
11
11
|
end
|
12
12
|
|
13
|
+
def write_attribute(key, value)
|
14
|
+
attr = key.to_sym
|
15
|
+
|
16
|
+
# The attribute already has an unsaved change.
|
17
|
+
if changed_attributes.include?(attr)
|
18
|
+
old = changed_attributes[attr]
|
19
|
+
changed_attributes.delete(attr) if value == old
|
20
|
+
else
|
21
|
+
old = clone_attribute_value(attr)
|
22
|
+
changed_attributes[attr] = old unless value == old
|
23
|
+
end
|
24
|
+
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
13
28
|
# Returns the attributes as they were before any changes were made to the document.
|
14
29
|
def original_attributes
|
15
30
|
{}.with_indifferent_access.merge(attributes).merge(changed_attributes)
|
16
31
|
end
|
17
|
-
|
32
|
+
|
18
33
|
protected
|
19
34
|
def changed_attributes
|
20
|
-
|
35
|
+
@changed_attributes ||= {}.with_indifferent_access
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def clone_attribute_value(attribute_name)
|
40
|
+
value = self[attribute_name.to_sym]
|
41
|
+
value.duplicable? ? value.clone : value
|
42
|
+
rescue TypeError, NoMethodError
|
43
|
+
value
|
21
44
|
end
|
22
45
|
end
|
23
46
|
end
|
data/lib/mongomodel/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongomodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 18
|
10
|
+
version: 0.2.18
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Pohlenz
|
@@ -132,7 +132,6 @@ files:
|
|
132
132
|
- autotest/discover.rb
|
133
133
|
- bin/console
|
134
134
|
- lib/mongomodel.rb
|
135
|
-
- lib/mongomodel/attributes/dirty.rb
|
136
135
|
- lib/mongomodel/attributes/mongo.rb
|
137
136
|
- lib/mongomodel/attributes/store.rb
|
138
137
|
- lib/mongomodel/attributes/typecasting.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module MongoModel
|
2
|
-
module Attributes
|
3
|
-
module Dirty
|
4
|
-
def []=(key, value)
|
5
|
-
attr = key.to_sym
|
6
|
-
|
7
|
-
# The attribute already has an unsaved change.
|
8
|
-
if changed.include?(attr)
|
9
|
-
old = changed[attr]
|
10
|
-
changed.delete(attr) if value == old
|
11
|
-
else
|
12
|
-
old = clone_attribute_value(attr)
|
13
|
-
changed[attr] = old unless value == old
|
14
|
-
end
|
15
|
-
|
16
|
-
super
|
17
|
-
end
|
18
|
-
|
19
|
-
def changed
|
20
|
-
@changed ||= {}.with_indifferent_access
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def clone_attribute_value(attribute_name)
|
25
|
-
value = self[attribute_name.to_sym]
|
26
|
-
value.duplicable? ? value.clone : value
|
27
|
-
rescue TypeError, NoMethodError
|
28
|
-
value
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|