api-blueprint 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/api-blueprint/cache.rb +10 -6
- data/lib/api-blueprint/model.rb +1 -0
- data/lib/api-blueprint/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c71a6912bd0d28aacda1dcc3e9270f589c27bd1a
|
4
|
+
data.tar.gz: c1a7c264ad6a56025a7a92bde195dc450c0a188b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c236b537499de0c80d39489c61ae7bdc86235279000a14f86aa0d3db66cacab2eada10b40b38733648263653ce7341c7aa73f75f27d00999f24484ac8169ff
|
7
|
+
data.tar.gz: 6142c601a95a4fa9eefb25653d1e9fc8b459591d8128241ff3ac5d1cf240189bc795a261d2d8ee9e2258fd2012af59c6a2c0e00a0080b5185fa5797dd2d28601
|
data/README.md
CHANGED
@@ -264,6 +264,20 @@ For example, to not include "X-Real-IP" and "X-Request-Id" headers, which would
|
|
264
264
|
end
|
265
265
|
```
|
266
266
|
|
267
|
+
If you would like to override how the cache keys are generated, you can do it for all classes by redefining `generate_cache_key` in your cache class. If you only need to override the cache key for certain models (for example, a public api cache might not want to use the session id to make the cache keys unique), you can do so by implementing a `cache_key_generator` proc on your model config:
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
class AstronautsInSpace < ApiBlueprint::Model
|
271
|
+
configure do |config|
|
272
|
+
config.cache_key_generator = -> (key, options) do
|
273
|
+
# `key` is the key which you have initialized the instance of the cache class with
|
274
|
+
# `options` is all the api-related options for the request (url, headers, body, etc)
|
275
|
+
"some-custom-cache-key-here"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
```
|
280
|
+
|
267
281
|
## A note on Dry::Struct immutability
|
268
282
|
|
269
283
|
Models you create use `Dry::Struct` to handle initialization and assignment. `Dry::Struct` is designed with immutability in mind, so if you need to mutate the objects you have, there are two possibilities; explicitly define an `attr_writer` for the attributes which you want to mutate, or do things the "Dry::Struct way" and use the current instance to initialize a new instance:
|
data/lib/api-blueprint/cache.rb
CHANGED
@@ -20,13 +20,17 @@ module ApiBlueprint
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def generate_cache_key(klass, options)
|
23
|
-
if
|
24
|
-
|
25
|
-
|
23
|
+
if klass&.cache_key_generator&.present?
|
24
|
+
klass.cache_key_generator.call key, options
|
25
|
+
else
|
26
|
+
if options.is_a? Hash
|
27
|
+
options = options.clone.with_indifferent_access.except :body
|
28
|
+
options[:headers] = options[:headers].except *self.class.config.ignored_headers if options[:headers]
|
29
|
+
end
|
30
|
+
|
31
|
+
options_digest = Digest::MD5.hexdigest Marshal::dump(options.to_s.chars.sort.join)
|
32
|
+
"#{key}:#{klass&.name}:#{options_digest}"
|
26
33
|
end
|
27
|
-
|
28
|
-
options_digest = Digest::MD5.hexdigest Marshal::dump(options.to_s.chars.sort.join)
|
29
|
-
"#{key}:#{klass&.name}:#{options_digest}"
|
30
34
|
end
|
31
35
|
|
32
36
|
end
|
data/lib/api-blueprint/model.rb
CHANGED
@@ -11,6 +11,7 @@ module ApiBlueprint
|
|
11
11
|
setting :builder, Builder.new
|
12
12
|
setting :replacements, {}
|
13
13
|
setting :log_responses, false
|
14
|
+
setting :cache_key_generator, nil, reader: true
|
14
15
|
|
15
16
|
attribute :response_headers, Types::Hash.optional
|
16
17
|
attribute :response_status, Types::Integer.optional
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-blueprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-types
|