kaminari-cache 0.2.0 → 0.2.1

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: bc756bf9a9f6776df73096cc3d33a38c39344f44
4
- data.tar.gz: 656f41364b790bd5b32f9b99d9681aaec6f90054
3
+ metadata.gz: 7d81b9849b289d81b82e69d267d2545ebd1b8dfd
4
+ data.tar.gz: c8e200c01ea5902312bc445efbe49dc48a6503d8
5
5
  SHA512:
6
- metadata.gz: faa5fdc2f2fdbf248c59d63e945ca43dc6d7780571830e8c8d98058e39ecb10f98df998e1edcdcedeb915b165c0d12914a639d9a95d3ace9d43ec79220f2d9b5
7
- data.tar.gz: 809b04e56b0ed82f009627002bcfccec9b3abf2afca0e4742c2738e1a888f6bb198ba4562c2ffffaf9b89f09db06319ddfd02956f5a7e153e406fe969054e221
6
+ metadata.gz: b1c389bb91168c6f88a6adae8e31f1af7c55050c56ce21daccaaf3209b6da75856a3006227c8893dab834d9fb66e3f1d72cee36f1e4e4e2099737ee068aed482
7
+ data.tar.gz: c80f3c930b39eaee793af4325b74d41e3b9967f7cef609490c1259fcd5101516efdde8060db36ec6e2a8b16458c5dfb7dda5f241b5f086f92e7314f3b4714d54
data/README.md CHANGED
@@ -33,6 +33,9 @@ In your controller:
33
33
  :start => :desc,
34
34
  :updated_at => :desc
35
35
  }
36
+ # :locale => :fr,
37
+ # :scope => :latest,
38
+ # :includes => :occurrences
36
39
  ```
37
40
 
38
41
  In your view:
@@ -42,6 +45,18 @@ In your view:
42
45
  end
43
46
  ```
44
47
 
48
+ **Note** that `fetch_page` returns an array of type `Kaminari::PaginatableArray` so if you use something like *Draper* which decorates *ActiveRecord* collections, you'll need to decorate them manualy and delegate the needed methods:
49
+
50
+ In an initializer (config/initializers/draper.rb):
51
+ ```ruby
52
+ Draper::CollectionDecorator.delegate :current_page, :total_pages, :limit_value, :total_count
53
+ ```
54
+
55
+ In your controller:
56
+ ```ruby
57
+ @events = Draper::CollectionDecorator.new Event.fetch_page(...)
58
+ ```
59
+
45
60
  ## TODO
46
61
 
47
62
  * Testing!
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "kaminari-cache"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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-10"
12
+ s.date = "2013-11-30"
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 = [
@@ -40,9 +40,11 @@ module KaminariCache
40
40
  key = cache_key(options)
41
41
  entries = Rails.cache.fetch(key) do
42
42
  Rails.logger.info "Cache miss: #{key.to_s}"
43
- scope = self.page(options[:page]).per(options[:per])
44
- scope = apply_sort(scope, options[:order]) if options[:order]
43
+ scope = self.send(options[:scope]) if options[:scope]
44
+ scope = (scope || self).page(options[:page]).per(options[:per])
45
45
  scope = apply_locale(scope, options[:locale]) if options[:locale]
46
+ scope = apply_includes(scope, options[:includes]) if options[:includes]
47
+ scope = apply_sort(scope, options[:order]) if options[:order]
46
48
  Kaminari::PaginatableArray.new(scope.to_a,
47
49
  :limit => scope.limit_value,
48
50
  :offset => scope.offset_value,
@@ -58,6 +60,8 @@ module KaminariCache
58
60
  key << options[:per]
59
61
  key << [:locale, options[:locale]] if options[:locale]
60
62
  key << [:order, options[:order]] if options[:order]
63
+ key << [:scope, options[:scope]] if options[:scope]
64
+ key << [:includes, options[:includes]] if options[:includes]
61
65
  expanded_key(key)
62
66
  end
63
67
 
@@ -97,6 +101,12 @@ module KaminariCache
97
101
  scope = scope.with_translations(locale) if scope.respond_to? :with_translations
98
102
  scope
99
103
  end
104
+ def apply_includes(scope, includes)
105
+ includes.each do |i|
106
+ scope = scope.includes(i)
107
+ end
108
+ scope
109
+ end
100
110
  end
101
111
  end
102
112
 
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.2.0
4
+ version: 0.2.1
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-10 00:00:00.000000000 Z
11
+ date: 2013-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kaminari-cache