actionpack-action_caching 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46985f5100e616356e19180b326cd2fc84f89e4d
4
+ data.tar.gz: 2c0cd050374dc9d7752b2709ebac2871e5475713
5
+ SHA512:
6
+ metadata.gz: 5146b22ed763f34e220736db5d9c8ddb439d711897fcb0163e081f69b35e2b74c9da5b14580efbb2aa1d4c18af57bfa1524b504ac1d935418d3a92f78f943392
7
+ data.tar.gz: bc868db0275461bdd6acdcb10005cda5ba75089b6545a9fb71367812c6ad4f39ab26dfbe54e8e7f062b17fc8df8154f8b509366a91af6fcb171656af1c810dac
data/.travis.yml CHANGED
@@ -3,6 +3,14 @@ before_install:
3
3
  - gem install bundler
4
4
  rvm:
5
5
  - 1.9.3
6
+ - 2.0.0
7
+ gemfile:
8
+ - Gemfile
9
+ - gemfiles/Gemfile-edge
10
+ - gemfiles/Gemfile-4-0-stable
11
+ matrix:
12
+ allow_failures:
13
+ - gemfile: gemfiles/Gemfile-edge
6
14
  notifications:
7
15
  email: false
8
16
  irc:
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ ## 1.1.0
2
+
3
+ * Allow to use non-proc object in `cache_path` option. You can pass an object that
4
+ responds to a `call` method.
5
+
6
+ Example:
7
+
8
+ class CachePath
9
+ def call(controller)
10
+ controller.id
11
+ end
12
+ end
13
+
14
+ class TestController < ApplicationController
15
+ caches_action :index, :cache_path => CachePath.new
16
+ def index; end
17
+ end
18
+
19
+ *Piotr Niełacny*
20
+
21
+ ## 1.0.0 (February 28, 2013)
22
+
23
+ * Extract Action Pack - Action Caching from Rails core.
24
+
25
+ *Francesco Rodriguez*
data/Gemfile CHANGED
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 4.0.0.beta1'
5
+ gem 'rails'
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  actionpack-action_caching
2
2
  =========================
3
3
 
4
- Action caching for Action Pack (removed from core in Rails 4.0)
4
+ Action caching for Action Pack (removed from core in Rails 4.0).
5
+
6
+ **NOTE:** It will continue to be officially maintained until Rails 4.1.
5
7
 
6
8
  Installation
7
9
  ------------
@@ -85,7 +87,7 @@ The following example depicts some of the points made above:
85
87
 
86
88
  caches_action :feed, cache_path: Proc.new do
87
89
  if params[:user_id]
88
- user_list_url(params[:user_id, params[:id])
90
+ user_list_url(params[:user_id], params[:id])
89
91
  else
90
92
  list_url(params[:id])
91
93
  end
@@ -113,3 +115,9 @@ Contributing
113
115
  3. Commit your changes (`git commit -am 'Add some feature'`).
114
116
  4. Push to the branch (`git push origin my-new-feature`).
115
117
  5. Create a new Pull Request.
118
+
119
+ Code Status
120
+ -----------
121
+
122
+ * [![Build Status](https://travis-ci.org/rails/actionpack-action_caching.png?branch=master)](https://travis-ci.org/rails/actionpack-action_caching)
123
+ * [![Dependency Status](https://gemnasium.com/rails/actionpack-action_caching.png)](https://gemnasium.com/rails/actionpack-action_caching)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'actionpack-action_caching'
5
- gem.version = '1.0.0'
5
+ gem.version = '1.1.0'
6
6
  gem.author = 'David Heinemeier Hansson'
7
7
  gem.email = 'david@loudthinking.com'
8
8
  gem.description = 'Action caching for Action Pack (removed from core in Rails 4.0)'
@@ -14,8 +14,8 @@ Gem::Specification.new do |gem|
14
14
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
15
  gem.require_paths = ['lib']
16
16
 
17
- gem.add_dependency 'actionpack', '>= 4.0.0.beta', '< 5.0'
17
+ gem.add_dependency 'actionpack', '>= 4.0.0', '< 5.0'
18
18
 
19
19
  gem.add_development_dependency 'mocha'
20
- gem.add_development_dependency 'activerecord', '>= 4.0.0.beta', '< 5.0'
20
+ gem.add_development_dependency 'activerecord', '>= 4.0.0.beta', '< 5'
21
21
  end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', github: 'rails/rails', branch: '4-0-stable'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', github: 'rails/rails', branch: 'master'
@@ -36,13 +36,15 @@ module ActionController
36
36
  # are treated like separate requests and so are cached separately.
37
37
  # Keep in mind when expiring an action cache that
38
38
  # <tt>action: 'lists'</tt> is not the same as
39
- # <tt>action: 'list', format: :xml</tt>.
39
+ # <tt>action: 'lists', format: :xml</tt>.
40
40
  #
41
41
  # You can modify the default action cache path by passing a
42
42
  # <tt>:cache_path</tt> option. This will be passed directly to
43
43
  # <tt>ActionCachePath.new</tt>. This is handy for actions with
44
44
  # multiple possible routes that should be cached differently. If a
45
45
  # block is given, it is called with the current controller instance.
46
+ # If an object that responds to <tt>call</tt> is given, it'll be called
47
+ # with the current controller instance.
46
48
  #
47
49
  # And you can also use <tt>:if</tt> (or <tt>:unless</tt>) to pass a
48
50
  # proc that specifies when the action should be cached.
@@ -52,6 +54,17 @@ module ActionController
52
54
  #
53
55
  # The following example depicts some of the points made above:
54
56
  #
57
+ # class CachePathCreator
58
+ # def initialize(name)
59
+ # @name = name
60
+ # end
61
+ #
62
+ # def call(controller)
63
+ # "cache-path-#{@name}"
64
+ # end
65
+ # end
66
+ #
67
+ #
55
68
  # class ListsController < ApplicationController
56
69
  # before_filter :authenticate, except: :public
57
70
  #
@@ -71,6 +84,8 @@ module ActionController
71
84
  # list_url(params[:id])
72
85
  # end
73
86
  # end
87
+ #
88
+ # caches_action :posts, cache_path: CachePathCreator.new('posts')
74
89
  # end
75
90
  #
76
91
  # If you pass <tt>layout: false</tt>, it will only cache your action
@@ -139,8 +154,10 @@ module ActionController
139
154
  def around(controller)
140
155
  cache_layout = @cache_layout.respond_to?(:call) ? @cache_layout.call(controller) : @cache_layout
141
156
 
142
- path_options = if @cache_path.respond_to?(:call)
157
+ path_options = if @cache_path.is_a?(Proc)
143
158
  controller.instance_exec(controller, &@cache_path)
159
+ elsif @cache_path.respond_to?(:call)
160
+ @cache_path.call(controller)
144
161
  else
145
162
  @cache_path
146
163
  end
data/test/caching_test.rb CHANGED
@@ -10,6 +10,12 @@ class CachingController < ActionController::Base
10
10
  self.cache_store = :file_store, FILE_STORE_PATH
11
11
  end
12
12
 
13
+ class CachePath
14
+ def call(controller)
15
+ ['controller', controller.params[:id]].compact.join('-')
16
+ end
17
+ end
18
+
13
19
  class ActionCachingTestController < CachingController
14
20
  rescue_from(Exception) { head 500 }
15
21
  rescue_from(ActionController::UnknownFormat) { head :not_acceptable }
@@ -23,6 +29,7 @@ class ActionCachingTestController < CachingController
23
29
  caches_action :index, :redirected, :forbidden, if: Proc.new { |c| c.request.format && !c.request.format.json? }, expires_in: 1.hour
24
30
  caches_action :show, cache_path: 'http://test.host/custom/show'
25
31
  caches_action :edit, cache_path: Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : 'http://test.host/edit' }
32
+ caches_action :custom_cache_path, cache_path: CachePath.new
26
33
  caches_action :with_layout
27
34
  caches_action :with_format_and_http_param, cache_path: Proc.new { |c| { key: 'value' } }
28
35
  caches_action :layout_false, layout: false
@@ -73,6 +80,7 @@ class ActionCachingTestController < CachingController
73
80
  alias_method :show, :index
74
81
  alias_method :edit, :index
75
82
  alias_method :destroy, :index
83
+ alias_method :custom_cache_path, :index
76
84
  alias_method :layout_false, :with_layout
77
85
  alias_method :with_layout_proc_param, :with_layout
78
86
 
@@ -291,6 +299,16 @@ class ActionCacheTest < ActionController::TestCase
291
299
  assert fragment_exist?('test.host/1;edit')
292
300
  end
293
301
 
302
+ def test_action_cache_with_custom_cache_path_with_custom_object
303
+ get :custom_cache_path
304
+ assert_response :success
305
+ assert fragment_exist?('controller')
306
+
307
+ get :custom_cache_path, id: 1
308
+ assert_response :success
309
+ assert fragment_exist?('controller-1')
310
+ end
311
+
294
312
  def test_cache_expiration
295
313
  get :index
296
314
  assert_response :success
metadata CHANGED
@@ -1,76 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack-action_caching
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Heinemeier Hansson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
11
+ date: 2013-11-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: actionpack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
- version: 4.0.0.beta
19
+ version: 4.0.0
22
20
  - - <
23
21
  - !ruby/object:Gem::Version
24
22
  version: '5.0'
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
- - - ! '>='
27
+ - - '>='
31
28
  - !ruby/object:Gem::Version
32
- version: 4.0.0.beta
29
+ version: 4.0.0
33
30
  - - <
34
31
  - !ruby/object:Gem::Version
35
32
  version: '5.0'
36
33
  - !ruby/object:Gem::Dependency
37
34
  name: mocha
38
35
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
- - - ! '>='
37
+ - - '>='
42
38
  - !ruby/object:Gem::Version
43
39
  version: '0'
44
40
  type: :development
45
41
  prerelease: false
46
42
  version_requirements: !ruby/object:Gem::Requirement
47
- none: false
48
43
  requirements:
49
- - - ! '>='
44
+ - - '>='
50
45
  - !ruby/object:Gem::Version
51
46
  version: '0'
52
47
  - !ruby/object:Gem::Dependency
53
48
  name: activerecord
54
49
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
50
  requirements:
57
- - - ! '>='
51
+ - - '>='
58
52
  - !ruby/object:Gem::Version
59
53
  version: 4.0.0.beta
60
54
  - - <
61
55
  - !ruby/object:Gem::Version
62
- version: '5.0'
56
+ version: '5'
63
57
  type: :development
64
58
  prerelease: false
65
59
  version_requirements: !ruby/object:Gem::Requirement
66
- none: false
67
60
  requirements:
68
- - - ! '>='
61
+ - - '>='
69
62
  - !ruby/object:Gem::Version
70
63
  version: 4.0.0.beta
71
64
  - - <
72
65
  - !ruby/object:Gem::Version
73
- version: '5.0'
66
+ version: '5'
74
67
  description: Action caching for Action Pack (removed from core in Rails 4.0)
75
68
  email: david@loudthinking.com
76
69
  executables: []
@@ -79,11 +72,14 @@ extra_rdoc_files: []
79
72
  files:
80
73
  - .gitignore
81
74
  - .travis.yml
75
+ - CHANGELOG.md
82
76
  - Gemfile
83
77
  - LICENSE.txt
84
78
  - README.md
85
79
  - Rakefile
86
80
  - actionpack-action_caching.gemspec
81
+ - gemfiles/Gemfile-4-0-stable
82
+ - gemfiles/Gemfile-edge
87
83
  - lib/action_controller/action_caching.rb
88
84
  - lib/action_controller/caching/actions.rb
89
85
  - lib/actionpack/action_caching.rb
@@ -92,30 +88,28 @@ files:
92
88
  - test/fixtures/layouts/talk_from_action.erb
93
89
  homepage: https://github.com/rails/actionpack-action_caching
94
90
  licenses: []
91
+ metadata: {}
95
92
  post_install_message:
96
93
  rdoc_options: []
97
94
  require_paths:
98
95
  - lib
99
96
  required_ruby_version: !ruby/object:Gem::Requirement
100
- none: false
101
97
  requirements:
102
- - - ! '>='
98
+ - - '>='
103
99
  - !ruby/object:Gem::Version
104
100
  version: '0'
105
101
  required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
102
  requirements:
108
- - - ! '>='
103
+ - - '>='
109
104
  - !ruby/object:Gem::Version
110
105
  version: '0'
111
106
  requirements: []
112
107
  rubyforge_project:
113
- rubygems_version: 1.8.23
108
+ rubygems_version: 2.0.3
114
109
  signing_key:
115
- specification_version: 3
110
+ specification_version: 4
116
111
  summary: Action caching for Action Pack (removed from core in Rails 4.0)
117
112
  test_files:
118
113
  - test/abstract_unit.rb
119
114
  - test/caching_test.rb
120
115
  - test/fixtures/layouts/talk_from_action.erb
121
- has_rdoc: