db_memoize 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/db_memoize/model.rb +17 -8
- data/lib/db_memoize/version.rb +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: b069a7997527c5e150d4a839c53a314dd08eda4e
|
4
|
+
data.tar.gz: c8ef2bf890ba4d091e159f95d00a92ec39fa559c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ac0719a0201decd8f2f14585aac6b565cbf59f8dfa0ce001c9eb639f8d651f7b21bfa64f1955a9c72e5ee207a16cedcb76d4ab093f721fd3b60a63aa22ec539
|
7
|
+
data.tar.gz: 4d12e206e5510eec4527bcca2a033ce1bccdbcc04c3233859905b32aacbb2088609388f8a7ca5308288cfb22b639e5102ac0951e05f913663e966f0f840bd47c
|
data/lib/db_memoize/model.rb
CHANGED
@@ -30,13 +30,26 @@ module DbMemoize
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def unmemoize(method_name = :all)
|
33
|
-
|
33
|
+
if method_name != :all
|
34
|
+
# FIXME: this works, but isn't immediately visible on the record
|
35
|
+
memoized_values.where(method_name: method_name).delete_all
|
36
|
+
else
|
37
|
+
memoized_values.clear
|
38
|
+
end
|
34
39
|
end
|
35
40
|
|
36
41
|
def memoized_custom_key
|
37
42
|
::DbMemoize.default_custom_key
|
38
43
|
end
|
39
44
|
|
45
|
+
def memoize_values(values, *args)
|
46
|
+
args_hash = ::Digest::MD5.hexdigest(Marshal.dump(args))
|
47
|
+
|
48
|
+
values.each do |name, value|
|
49
|
+
create_memoized_value(name, args_hash, value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
40
53
|
private
|
41
54
|
|
42
55
|
def create_memoized_value(method_name, args_hash, value)
|
@@ -77,14 +90,10 @@ module DbMemoize
|
|
77
90
|
DbMemoize::Value.where(conditions).delete_all
|
78
91
|
end
|
79
92
|
|
80
|
-
def memoize_values(records_or_ids, values)
|
93
|
+
def memoize_values(records_or_ids, values, *args)
|
81
94
|
transaction do
|
82
95
|
ids = find_ids(records_or_ids)
|
83
|
-
args_hash = ::Digest::MD5.hexdigest(Marshal.dump(
|
84
|
-
|
85
|
-
values = values.inject({}) do |hsh, (key, value)|
|
86
|
-
hsh.merge(key => Marshal.dump(value))
|
87
|
-
end
|
96
|
+
args_hash = ::Digest::MD5.hexdigest(Marshal.dump(args))
|
88
97
|
|
89
98
|
ids.each do |id|
|
90
99
|
values.each do |name, value|
|
@@ -94,7 +103,7 @@ module DbMemoize
|
|
94
103
|
method_name: name,
|
95
104
|
arguments_hash: args_hash,
|
96
105
|
custom_key: DbMemoize.default_custom_key.to_s,
|
97
|
-
value: value
|
106
|
+
value: Marshal.dump(value)
|
98
107
|
)
|
99
108
|
end
|
100
109
|
end
|
data/lib/db_memoize/version.rb
CHANGED