kaminari-cache 0.1.3 → 0.1.4

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: cd346ed313038cb55c741d06729a13c6dcea10ba
4
- data.tar.gz: aeaacf07a5d424d1a82cacdb655d5e251cc310f7
3
+ metadata.gz: 40a6c8743a9b33e40dabbca3cfb4e6c9b68122d3
4
+ data.tar.gz: 0e066aca66deda9ba7110f936781dee0e410ad5f
5
5
  SHA512:
6
- metadata.gz: 91c3ca3fb42ba66bf26149429a23a27a4df27c2f186ee05a98e983f188d36f9280cb2ac3c992579013fc744816e6d47410103493bcc08dd75f6c3d65776737c6
7
- data.tar.gz: c94a58db9708c84896ca19668fcbb7a5463cf5047eef7256bc3840dc373af0833900ab0243e6723663f9cffa0df583381bda16a0ecee48aef6d0424bf1f2c527
6
+ metadata.gz: 99c31e7aa6e5859939826fb112c71d5f5097f58b48966f5ffe3515c2b1af8d8474da690bbf36d8b992eb2897d4711acb8675808fb7982daedeb555cbda291efc
7
+ data.tar.gz: ffc6ab33fea68aaf79d5441e824f7082efac2360b9f1ce00466b3d1c4ae65491fca3db82eba84966a13a4925b4d9544ff80d1883f78304ab8277812bbdeca9cc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "kaminari-cache"
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jim"]
12
- s.date = "2013-11-05"
12
+ s.date = "2013-11-10"
13
13
  s.description = "Kaminari Cache is a simple caching layer and sweeper for Kaminari pagination"
14
14
  s.email = "powerjim@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -37,9 +37,12 @@ module KaminariCache
37
37
  :page => 1,
38
38
  :per => Kaminari.config.max_per_page || Kaminari.config.default_per_page
39
39
  )
40
- entries = Rails.cache.fetch(cache_key(options)) do
40
+ key = cache_key(options)
41
+ entries = Rails.cache.fetch(key) do
42
+ Rails.logger.info "Cache miss: #{key.to_s}"
41
43
  scope = self.page(options[:page]).per(options[:per])
42
- scope = apply_sort(scope, options[:order])
44
+ scope = apply_sort(scope, options[:order]) if options[:order]
45
+ scope = apply_locale(scope, options[:locale]) if options[:locale]
43
46
  Kaminari::PaginatableArray.new(scope.to_a,
44
47
  :limit => scope.limit_value,
45
48
  :offset => scope.offset_value,
@@ -48,32 +51,53 @@ module KaminariCache
48
51
  end
49
52
  end
50
53
 
51
- def cache_key(options)
52
- key = [:kaminari, self.name.downcase]
53
- key << options[:page]
54
- key << options[:per]
55
- key << ["order", options[:order]] if options[:order]
56
- key
57
- end
54
+ private
55
+ def cache_key(options)
56
+ key = [:kaminari, self.name.pluralize.downcase]
57
+ key << options[:page]
58
+ key << options[:per]
59
+ key << [:locale, options[:locale]] if options[:locale]
60
+ key << [:order, options[:order]] if options[:order]
61
+ expanded_key(key)
62
+ end
58
63
 
59
- def apply_sort(scope, order)
60
- case order
61
- when Symbol
62
- scope.order! order
63
- when String
64
- scope.order! order
65
- when Hash
66
- order.each do |k, v|
67
- if v.empty?
68
- scope.order! k
64
+ def expanded_key(key)
65
+ return key.cache_key.to_s if key.respond_to?(:cache_key)
66
+ case key
67
+ when Array
68
+ if key.size > 1
69
+ key = key.collect{|element| expanded_key(element)}
69
70
  else
70
- scope.order! "#{k.to_s} #{v.to_s}"
71
+ key = key.first
71
72
  end
72
- end
73
+ when Hash
74
+ key = key.sort_by { |k,_| k.to_s }.collect{|k,v| "#{k}=#{v}"}
75
+ end
76
+ key.to_param
77
+ end
78
+
79
+ def apply_sort(scope, order)
80
+ case order
81
+ when Symbol
82
+ scope.order! order
83
+ when String
84
+ scope.order! order
85
+ when Hash
86
+ order.each do |k, v|
87
+ if v.empty?
88
+ scope.order! k
89
+ else
90
+ scope.order! "#{k.to_s} #{v.to_s}"
91
+ end
92
+ end
93
+ end
94
+ scope
95
+ end
96
+ def apply_locale(scope, locale)
97
+ scope = scope.with_translations(locale) if scope.respond_to? :with_translations
98
+ scope
73
99
  end
74
- scope
75
100
  end
76
- end
77
101
  end
78
102
 
79
103
  ActiveRecord::Base.send(:include, KaminariCache)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaminari-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-05 00:00:00.000000000 Z
11
+ date: 2013-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kaminari-cache