attribute_cache 0.2.1 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a461cfe2ed010a9b5934d7f3638d7506342e791b1fa6e6fca2e26d16d16aaca3
4
- data.tar.gz: 379500bd4bf3b841a5e5f948bb7fbdf48129bf4218395e6f636774b5c2c134a3
3
+ metadata.gz: 9277d58389cc12d8fe481c8f71b11ee674e53b3b41bd99621629e2f4d71ef1d5
4
+ data.tar.gz: ef35ea8334091905661b22c1172f9e4c532abff4f4ff6bbc06bfc5aa835f686a
5
5
  SHA512:
6
- metadata.gz: d2b9e15cffd9de958d4985cb00ddf1c0d26108cdd6024020b391d47f411c789769192225084ac3573e075485dc8b283b3451a28f4a0ec69f7632209e720afa97
7
- data.tar.gz: 73201dbe32e5a13b3a4542311450a40514dad1750ef9727724d22f246b18cf5994c0af74e12206c91a44def83c798c4b62355e1e89d1acfb57cc02a9d4395234
6
+ metadata.gz: ec04f01cb5338ed9e04c0df25c64fd6366846da2134e56bd75c10d1205d64ec0339ecbd028455741428825a9a9feeec48774b5af2192e3d58f9b02ce2a4ec626
7
+ data.tar.gz: 987ff3d0f621f9a5ec4232b8f5ccef820b7032e7f4e1d0e2d171c9c04b822a61cf6102f562bc2d56c1eda491512176d6215978ecfef36742eb85a2e3942e8eb3
@@ -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
- set_attribute(record, save: save) if cached_value(record).nil? || !keep_blanks && cached_value(record).blank?
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
@@ -1,3 +1,3 @@
1
1
  module AttributeCache
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.3'
3
3
  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.1
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-19 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: first_existing