cache_crispies 1.0.1 → 1.0.2
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 +4 -4
- data/lib/cache_crispies/attribute.rb +8 -4
- data/lib/cache_crispies/base.rb +2 -1
- data/lib/cache_crispies/controller.rb +8 -3
- data/lib/cache_crispies/plan.rb +4 -5
- data/lib/cache_crispies/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: dde77903d49df53ae283abc8d1c0b93e9f8d849b8d1696d39fced6a664b005dd
|
4
|
+
data.tar.gz: e656b7ce6ce5e74076380b67fb5d86b6fe731a4df80edbb953c5e63694ce40de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb83071875231fa5ec31244d47e2594de335787515dafe75fd9ce433060e151b38469c7b06e2a5428c6e1746855ced29ca6cf25970bd874c3dae056936347478
|
7
|
+
data.tar.gz: be8908410852bc16ac94efe31b9972d384b82932fb791aad2e9e98df646386131fc260317e3b1d7d3c94e19f20ffc5e3c5951d0a87be67d68da88c7d8eb41cc4
|
@@ -14,6 +14,7 @@ module CacheCrispies
|
|
14
14
|
# @param from [Symbol] the method on the model to call to get the value
|
15
15
|
# @param with [CacheCrispies::Base] a serializer to use to serialize the
|
16
16
|
# @param to [Class, Symbol] the data type to coerce the value into
|
17
|
+
# @param collection [Boolean] force rendering as single or collection
|
17
18
|
# @param nesting [Array<Symbol>] the JSON keys this attribute will be
|
18
19
|
# nested inside
|
19
20
|
# @param conditions [Array<CacheCrispies::Condition>] the show_if condition
|
@@ -22,7 +23,8 @@ module CacheCrispies
|
|
22
23
|
# argument's value
|
23
24
|
def initialize(
|
24
25
|
key,
|
25
|
-
from: nil, with: nil, through: nil, to: nil,
|
26
|
+
from: nil, with: nil, through: nil, to: nil, collection: nil,
|
27
|
+
nesting: [], conditions: [],
|
26
28
|
&block
|
27
29
|
)
|
28
30
|
@key = key
|
@@ -30,6 +32,7 @@ module CacheCrispies
|
|
30
32
|
@serializer = with
|
31
33
|
@through = through
|
32
34
|
@coerce_to = to
|
35
|
+
@collection = collection
|
33
36
|
@nesting = Array(nesting)
|
34
37
|
@conditions = Array(conditions)
|
35
38
|
@block = block
|
@@ -41,6 +44,7 @@ module CacheCrispies
|
|
41
44
|
:serializer,
|
42
45
|
:through,
|
43
46
|
:coerce_to,
|
47
|
+
:collection,
|
44
48
|
:nesting,
|
45
49
|
:conditions,
|
46
50
|
:block
|
@@ -66,8 +70,6 @@ module CacheCrispies
|
|
66
70
|
serializer ? serialize(value, options) : coerce(value)
|
67
71
|
end
|
68
72
|
|
69
|
-
|
70
|
-
|
71
73
|
private
|
72
74
|
|
73
75
|
def through?
|
@@ -81,7 +83,9 @@ module CacheCrispies
|
|
81
83
|
# Here we'll render the attribute with a given serializer and attempt to
|
82
84
|
# cache the results for better cache reusability
|
83
85
|
def serialize(value, options)
|
84
|
-
plan = CacheCrispies::Plan.new(
|
86
|
+
plan = CacheCrispies::Plan.new(
|
87
|
+
serializer, value, collection: collection, **options
|
88
|
+
)
|
85
89
|
|
86
90
|
if plan.collection?
|
87
91
|
plan.cache { Collection.new(value, serializer, options).as_json }
|
data/lib/cache_crispies/base.rb
CHANGED
@@ -220,7 +220,7 @@ module CacheCrispies
|
|
220
220
|
|
221
221
|
def self.serialize(
|
222
222
|
*attribute_names,
|
223
|
-
from: nil, with: nil, through: nil, to: nil,
|
223
|
+
from: nil, with: nil, through: nil, to: nil, collection: nil,
|
224
224
|
&block
|
225
225
|
)
|
226
226
|
attribute_names.flatten.map { |att| att&.to_sym }.map do |attrib|
|
@@ -234,6 +234,7 @@ module CacheCrispies
|
|
234
234
|
with: with,
|
235
235
|
through: through,
|
236
236
|
to: to,
|
237
|
+
collection: collection,
|
237
238
|
nesting: current_nesting,
|
238
239
|
conditions: current_conditions,
|
239
240
|
&block
|
@@ -25,8 +25,13 @@ module CacheCrispies
|
|
25
25
|
# or Rails-supported symbol. See
|
26
26
|
# https://guides.rubyonrails.org/layouts_and_rendering.html#the-status-option
|
27
27
|
# @return [void]
|
28
|
-
def cache_render(serializer, cacheable,
|
29
|
-
plan = CacheCrispies::Plan.new(
|
28
|
+
def cache_render(serializer, cacheable, key: nil, collection: nil, status: nil, **options)
|
29
|
+
plan = CacheCrispies::Plan.new(
|
30
|
+
serializer,
|
31
|
+
cacheable,
|
32
|
+
key: key, collection: collection,
|
33
|
+
**options
|
34
|
+
)
|
30
35
|
|
31
36
|
if CacheCrispies.config.etags?
|
32
37
|
response.weak_etag = plan.etag
|
@@ -44,7 +49,7 @@ module CacheCrispies
|
|
44
49
|
end
|
45
50
|
|
46
51
|
render_hash = { json: Oj.dump(plan.wrap(serializer_json), mode: OJ_MODE) }
|
47
|
-
render_hash[:status] =
|
52
|
+
render_hash[:status] = status if status
|
48
53
|
|
49
54
|
render render_hash
|
50
55
|
end
|
data/lib/cache_crispies/plan.rb
CHANGED
@@ -16,14 +16,13 @@ module CacheCrispies
|
|
16
16
|
# data under
|
17
17
|
# @option options [Boolean] :collection whether to render the data as a
|
18
18
|
# collection/array or a single object
|
19
|
-
def initialize(serializer, cacheable,
|
19
|
+
def initialize(serializer, cacheable, key: nil, collection: nil, **options)
|
20
20
|
@serializer = serializer
|
21
21
|
@cacheable = cacheable
|
22
22
|
|
23
|
-
|
24
|
-
@
|
25
|
-
@
|
26
|
-
@options = opts
|
23
|
+
@key = key
|
24
|
+
@collection = collection
|
25
|
+
@options = options
|
27
26
|
end
|
28
27
|
|
29
28
|
# Whether or not the cacheable should be treated like a collection
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_crispies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Crownoble
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|