cache_crispies 1.1.4 → 1.2.0

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
  SHA256:
3
- metadata.gz: dd2682e40adfbb9511562cc2b406cd5fa9731134977f1072c5e42684f88590b9
4
- data.tar.gz: 12c00d8ddd71b23daf0834db565334e0a1d71a28e37809b82d52717e940f16ec
3
+ metadata.gz: 144a9a90f1bceced6d4197add1047b29352f7cba8b89c19dd92e57411672d7c4
4
+ data.tar.gz: d6ad1a658628441972010ff169f56fe779b0edc2a8990522b4f49ff765b6f4ee
5
5
  SHA512:
6
- metadata.gz: 71ea2e90153a90ca9f1ae3d9d6b5e229a7f547f0fe271a6cbe8ec01bde10ec23e2736ef7a14898c7c9c48d2c17393b5ebe8bd7787b0123fd0bfc1868095007b1
7
- data.tar.gz: c029d5cd5a5b35f22494eeeed2f4b9a3bcffd64989c36b6cd8be2c8731eb032e34926f79b3f3e8f69ab9a84c57170bfc22cc4c06f5757774d6b37eb7ffc5f329
6
+ metadata.gz: f35f5dd51753129083e2ea3c6664709d1977e0255bd60d0a316d275ca6197de1b43cad1fd79bff13ffa9b7183a445f5de4955c45d66ff93a5bd8e30f26f8d37c
7
+ data.tar.gz: f29c05d0fd636e7648b6d4f14bbdd597fc91519669eb841797a1934e667653fa8706b276e3b592ea66217d7bf0c93d8294a259003d060de1d4b15f15f090878a
@@ -6,7 +6,8 @@ module CacheCrispies
6
6
  class Configuration
7
7
  SETTINGS = [
8
8
  :cache_store,
9
- :etags
9
+ :etags,
10
+ :cache_key_method
10
11
  ].freeze
11
12
 
12
13
  SETTINGS.each do |setting|
@@ -18,11 +19,13 @@ module CacheCrispies
18
19
  end
19
20
 
20
21
  alias etags? etags
22
+ alias cache_key_method? cache_key_method
21
23
 
22
24
  # Resets all values to their defaults. Useful for testing.
23
25
  def reset!
24
26
  @cache_store = Rails.cache || ActiveSupport::Cache::NullStore.new
25
27
  @etags = false
28
+ @cache_key_method = :cache_key
26
29
  end
27
30
  end
28
31
  end
@@ -58,7 +58,7 @@ module CacheCrispies
58
58
  serializer.cache_key_base,
59
59
  serializer.dependency_key,
60
60
  addons_key,
61
- cacheable.cache_key
61
+ cacheable_cache_key
62
62
  ].flatten.compact.join(CACHE_KEY_SEPARATOR)
63
63
  end
64
64
 
@@ -101,7 +101,11 @@ module CacheCrispies
101
101
  end
102
102
 
103
103
  def cache?
104
- serializer.do_caching? && cacheable.respond_to?(:cache_key)
104
+ serializer.do_caching? && cacheable.respond_to?(CacheCrispies.config.cache_key_method)
105
+ end
106
+
107
+ def cacheable_cache_key
108
+ cacheable.public_send(CacheCrispies.config.cache_key_method)
105
109
  end
106
110
 
107
111
  def addons_key
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CacheCrispies
4
4
  # The version of the gem
5
- VERSION = '1.1.4'
5
+ VERSION = '1.2.0'
6
6
  end
@@ -39,4 +39,16 @@ describe CacheCrispies::Configuration do
39
39
  }.to change { subject.etags }.to true
40
40
  end
41
41
  end
42
+
43
+ describe '#cache_key_method' do
44
+ it 'is cache_key by default' do
45
+ expect(subject.cache_key_method).to eq :cache_key
46
+ end
47
+
48
+ it 'can be changed' do
49
+ expect {
50
+ subject.cache_key_method = :other_cache_key
51
+ }.to change { subject.cache_key_method }.to eq :other_cache_key
52
+ end
53
+ end
42
54
  end
@@ -125,6 +125,17 @@ describe CacheCrispies::Plan do
125
125
  )
126
126
  end
127
127
  end
128
+
129
+ context 'with a configured cache_key_method' do
130
+ let(:custom_cache_key) { 'custom-cache-key' }
131
+ let(:model) { OpenStruct.new(name: 'Sugar Smacks', custom_cache_key: custom_cache_key) }
132
+
133
+ it "includes the cacheable #custom_cache_key" do
134
+ expect(CacheCrispies.config).to receive(:cache_key_method).and_return :custom_cache_key
135
+
136
+ expect(subject.cache_key).to include custom_cache_key
137
+ end
138
+ end
128
139
  end
129
140
 
130
141
  describe '#cache' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_crispies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
@@ -121,17 +121,31 @@ dependencies:
121
121
  - !ruby/object:Gem::Version
122
122
  version: 3.8.0
123
123
  - !ruby/object:Gem::Dependency
124
- name: simplecov
124
+ name: rspec_junit_formatter
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '0.17'
129
+ version: '0.4'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0.4'
137
+ - !ruby/object:Gem::Dependency
138
+ name: simplecov
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '='
142
+ - !ruby/object:Gem::Version
143
+ version: '0.17'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '='
135
149
  - !ruby/object:Gem::Version
136
150
  version: '0.17'
137
151
  description:
@@ -183,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
197
  - !ruby/object:Gem::Version
184
198
  version: '0'
185
199
  requirements: []
186
- rubygems_version: 3.1.2
200
+ rubygems_version: 3.2.0
187
201
  signing_key:
188
202
  specification_version: 4
189
203
  summary: Fast Rails serializer with built-in caching