cache_key_for 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: 8c625fdf466a0e82fa1c2bb3df30ffecf5044332
4
- data.tar.gz: e3d7c1ccf821298f34890920e4e31d4b8b1115bf
3
+ metadata.gz: b63791dd91d36103f05b7ed05d2277a2930e0e23
4
+ data.tar.gz: e2099e762d0e2a37064ad55f5544431c190297ff
5
5
  SHA512:
6
- metadata.gz: 37ad16b96072909e6d821841fae60050f7cf26b510857563b0671e50c0882aefb98b2eb39f26c975a42753b12da4c88a2fb521037e8a9acc92d5b886a9a3d017
7
- data.tar.gz: 5c991a6bfedacafc4f30526f37d6f0b4a7af555afba85a08e4850619cf104d1f24bcbec7e26ab16c6b770d9d5b74ea16ff8a8dc0c92787826d6cfdeb76784930
6
+ metadata.gz: 51ed14279d471dfcd0285d6a7504fbfd487ce6dcb86bfa696c3f16c8a236b1dcecd433eec1a0578fe762f387c0b4e070df85c0e1f879debbc56db3101aaf53f0
7
+ data.tar.gz: 0b2d4b9d7dab90f686c152429799d16020306fc604bc7ef4570ff2d73f995723f634d8ce604b20263744ca454e095185f6639f59c47a23f7f5e7259da42ffa0b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cache_key_for (0.1.2)
4
+ cache_key_for (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -132,4 +132,4 @@ DEPENDENCIES
132
132
  sqlite3 (~> 1.3)
133
133
 
134
134
  BUNDLED WITH
135
- 1.11.2
135
+ 1.12.3
data/README.md CHANGED
@@ -22,6 +22,7 @@ Features:
22
22
  * accepts `cache_owner_cache_key` for personalized cache, eg. current_company.cache_key, current_user.cache_key etc.
23
23
  * filters params with proper non-utf8 data handling for key generation
24
24
  * recognizes pagination via params (performs well for less than 100 objects per page)
25
+ * allows to set default page and per_page or sort order or any param in `default_params` to avoid multiple different default caches
25
26
  * includes all params, not only GET's `query` params, which enables submitting of complex forms via POST,
26
27
  which - otherwise - would have query string longer than 2048 characters (Microsoft Internet Explorer)
27
28
  * optional whitelist of first level parameters to prevent accidentally generating duplicated cache
@@ -7,6 +7,7 @@
7
7
  # * accepts `cache_owner_cache_key` for personalized cache, eg. current_company.cache_key, current_user.cache_key etc.
8
8
  # * filters params with proper non-utf8 data handling for key generation
9
9
  # * recognizes pagination via params (performs well for less than 100 objects per page)
10
+ # * allows to set default page and per_page or sort order or any param in `default_params` to avoid multiple different default caches
10
11
  # * includes all params, not only GET's `query` params, which enables submitting of complex forms via POST,
11
12
  # which - otherwise - would have query string longer than 2048 characters (Microsoft Internet Explorer)
12
13
  # * optional whitelist of first level parameters to prevent accidentally generating duplicated cache
@@ -41,16 +42,16 @@
41
42
  # app_name:views/en/datacenters/5bd92bd352e7726d02175752913014711f5d412e/companies/1-20150619101645935901000/2015-06-26/7a6f89a738006a69c1d1e0214e147bab
42
43
  # ```
43
44
  module CacheKeyForHelper
44
- def cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '', whitelist_params = [])
45
+ def cache_key_for(scoped_collection, collection_prefix, cache_owner_cache_key = '', suffix = '', whitelist_params = [], default_params = {})
45
46
  max_updated_at = scoped_collection.to_a.map { |i| i.updated_at ? i.updated_at.utc.to_f : 0 }.max
46
47
  count = scoped_collection.count
47
48
  ids_string = scoped_collection.to_a.map(&:id).join('-')
48
49
  blacklist_params = ['utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign']
49
50
  request_params = if request.params
50
51
  if whitelist_params.empty?
51
- request.params.reject { |k, _v| blacklist_params.include?(k.to_s) }
52
+ default_params.merge(request.params).reject { |k, _v| blacklist_params.include?(k.to_s) }
52
53
  else
53
- request.params.select { |k, _v| whitelist_params.include?(k.to_s) }
54
+ default_params.merge(request.params).select { |k, _v| whitelist_params.include?(k.to_s) }
54
55
  end.map { |k, v| [k.to_s.dup.force_encoding('UTF-8'), v.dup.to_s.force_encoding('UTF-8')] }
55
56
  else
56
57
  nil
@@ -1,3 +1,3 @@
1
1
  module CacheKeyFor
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_key_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Kalita
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal