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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7be596f4546279c27b355a83a6c87b5d986cbcc65779def4310df106c3017557
4
- data.tar.gz: e7b5ceb4ac6c68d7149bb45246bdba99864c5fbd289277d054b22c5c622f748d
3
+ metadata.gz: dde77903d49df53ae283abc8d1c0b93e9f8d849b8d1696d39fced6a664b005dd
4
+ data.tar.gz: e656b7ce6ce5e74076380b67fb5d86b6fe731a4df80edbb953c5e63694ce40de
5
5
  SHA512:
6
- metadata.gz: ac4fe247753da8c9afa3e2d5a27d8f673c780b6bbb0d71a8777e736e9b9761be4791c33e5370a3f6a1ade8df2ff65befd648c9004908f1d4ebaafb3ce3678aa1
7
- data.tar.gz: 823e1a06a9a007e74cb148751f765cf506e96849b5947e5132b2fffadfbaaa447a3c379cbd805d72fb03ceffd2bb8daf12a8649e282020d1d91b98656af97e82
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, nesting: [], conditions: [],
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(serializer, value, options)
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 }
@@ -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, options = {})
29
- plan = CacheCrispies::Plan.new(serializer, cacheable, options)
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] = options[:status] if options.key?(:status)
52
+ render_hash[:status] = status if status
48
53
 
49
54
  render render_hash
50
55
  end
@@ -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, options = {})
19
+ def initialize(serializer, cacheable, key: nil, collection: nil, **options)
20
20
  @serializer = serializer
21
21
  @cacheable = cacheable
22
22
 
23
- opts = options.dup
24
- @key = opts.delete(:key)
25
- @collection = opts.delete(:collection)
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CacheCrispies
4
4
  # The version of the gem
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
  end
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.1
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: 2019-10-12 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties