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 +4 -4
- data/README.md +15 -0
- data/VERSION +1 -1
- data/kaminari-cache.gemspec +2 -2
- data/lib/kaminari-cache.rb +12 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d81b9849b289d81b82e69d267d2545ebd1b8dfd
|
4
|
+
data.tar.gz: c8e200c01ea5902312bc445efbe49dc48a6503d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
1
|
+
0.2.1
|
data/kaminari-cache.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "kaminari-cache"
|
8
|
-
s.version = "0.2.
|
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-
|
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 = [
|
data/lib/kaminari-cache.rb
CHANGED
@@ -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.
|
44
|
-
scope =
|
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.
|
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-
|
11
|
+
date: 2013-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kaminari-cache
|