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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb29e0ed96c1c50d958a68b38522f9b9c89ab871
4
- data.tar.gz: 1b6c941e80d5994947d73268e2a56702c1cdebf2
3
+ metadata.gz: b069a7997527c5e150d4a839c53a314dd08eda4e
4
+ data.tar.gz: c8ef2bf890ba4d091e159f95d00a92ec39fa559c
5
5
  SHA512:
6
- metadata.gz: 866010486f596c3698d1610830741832caeeae05d8a54f29a20c7fb15043bb1491038244b84638f3451400c67cb15b08f766ae35cba128e4811700e5896f248e
7
- data.tar.gz: 0664db322d27c8ba957d8b708733d042b364e1cfce68bb056610866a5203f5b4dfae515cc1dd0584f2591bc419246c544275c1ed317ae11884ea398f778e4949
6
+ metadata.gz: 8ac0719a0201decd8f2f14585aac6b565cbf59f8dfa0ce001c9eb639f8d651f7b21bfa64f1955a9c72e5ee207a16cedcb76d4ab093f721fd3b60a63aa22ec539
7
+ data.tar.gz: 4d12e206e5510eec4527bcca2a033ce1bccdbcc04c3233859905b32aacbb2088609388f8a7ca5308288cfb22b639e5102ac0951e05f913663e966f0f840bd47c
@@ -30,13 +30,26 @@ module DbMemoize
30
30
  end
31
31
 
32
32
  def unmemoize(method_name = :all)
33
- self.class.unmemoize(self, method_name)
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
@@ -1,3 +1,3 @@
1
1
  module DbMemoize
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_memoize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - johannes-kostas goetzinger