attribute_cache 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attribute_cache.rb +10 -10
- data/lib/attribute_cache/attribute_cache.rb +11 -9
- data/lib/attribute_cache/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9277d58389cc12d8fe481c8f71b11ee674e53b3b41bd99621629e2f4d71ef1d5
|
4
|
+
data.tar.gz: ef35ea8334091905661b22c1172f9e4c532abff4f4ff6bbc06bfc5aa835f686a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec04f01cb5338ed9e04c0df25c64fd6366846da2134e56bd75c10d1205d64ec0339ecbd028455741428825a9a9feeec48774b5af2192e3d58f9b02ce2a4ec626
|
7
|
+
data.tar.gz: 987ff3d0f621f9a5ec4232b8f5ccef820b7032e7f4e1d0e2d171c9c04b822a61cf6102f562bc2d56c1eda491512176d6215978ecfef36742eb85a2e3942e8eb3
|
data/lib/attribute_cache.rb
CHANGED
@@ -39,24 +39,24 @@ module AttributeCache
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
define_method("set_#{name}") do |save: false|
|
43
|
-
attr_cache.set_attribute(self, save: save)
|
42
|
+
define_method("set_#{name}") do |save: false, args: []|
|
43
|
+
attr_cache.set_attribute(self, save: save, args: args)
|
44
44
|
end
|
45
45
|
|
46
|
-
define_method("invalidate_#{name}") do |save: false|
|
47
|
-
attr_cache.invalidate_attribute(self, save: save)
|
46
|
+
define_method("invalidate_#{name}") do |save: false, args: []|
|
47
|
+
attr_cache.invalidate_attribute(self, save: save, args: args)
|
48
48
|
end
|
49
49
|
|
50
|
-
define_method("set_#{name}!") do
|
51
|
-
attr_cache.set_attribute!(self)
|
50
|
+
define_method("set_#{name}!") do |args: []|
|
51
|
+
attr_cache.set_attribute!(self, args: args)
|
52
52
|
end
|
53
53
|
|
54
|
-
define_method("invalidate_#{name}!") do
|
55
|
-
attr_cache.invalidate_attribute!(self)
|
54
|
+
define_method("invalidate_#{name}!") do |args: []|
|
55
|
+
attr_cache.invalidate_attribute!(self, args: args)
|
56
56
|
end
|
57
57
|
|
58
|
-
define_method(name) do |save: true, keep_blanks: true|
|
59
|
-
attr_cache.value(self, save: save, keep_blanks: keep_blanks)
|
58
|
+
define_method(name) do |save: true, keep_blanks: true, args: []|
|
59
|
+
attr_cache.value(self, save: save, keep_blanks: keep_blanks, args: args)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -6,19 +6,21 @@ module AttributeCache
|
|
6
6
|
@callback = callback
|
7
7
|
end
|
8
8
|
|
9
|
-
def set_attribute(record, save: false)
|
10
|
-
record.write_attribute(@attribute, execute_callback(record))
|
9
|
+
def set_attribute(record, save: false, args: [])
|
10
|
+
record.write_attribute(@attribute, execute_callback(record, *args))
|
11
11
|
record.save if save
|
12
12
|
end
|
13
13
|
alias invalidate_attribute set_attribute
|
14
14
|
|
15
|
-
def set_attribute!(record)
|
16
|
-
set_attribute(record, save: true)
|
15
|
+
def set_attribute!(record, args: [])
|
16
|
+
set_attribute(record, save: true, args: args)
|
17
17
|
end
|
18
18
|
alias invalidate_attribute! set_attribute!
|
19
19
|
|
20
|
-
def value(record, save:, keep_blanks:)
|
21
|
-
|
20
|
+
def value(record, save:, keep_blanks:, args: [])
|
21
|
+
if cached_value(record).nil? || !keep_blanks && cached_value(record).blank?
|
22
|
+
set_attribute(record, save: save, args: args)
|
23
|
+
end
|
22
24
|
cached_value(record)
|
23
25
|
end
|
24
26
|
|
@@ -28,12 +30,12 @@ module AttributeCache
|
|
28
30
|
record.read_attribute(@attribute)
|
29
31
|
end
|
30
32
|
|
31
|
-
def execute_callback(record)
|
33
|
+
def execute_callback(record, *args)
|
32
34
|
case @callback
|
33
35
|
when Symbol, String
|
34
|
-
record.send(@callback)
|
36
|
+
record.send(@callback, *args)
|
35
37
|
when Proc
|
36
|
-
@callback[]
|
38
|
+
@callback[*args]
|
37
39
|
else
|
38
40
|
raise 'An invalid callback was provided!'
|
39
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Lockard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: first_existing
|