patch_utils 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. metadata +2 -3
  3. data/lib/patch_utils/actions.rb +0 -82
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6612a4b31eecf9678c515beda31029563112a41
4
- data.tar.gz: e997d0767bd912bc0cd60479935c49887fb9f704
3
+ metadata.gz: 10a5d7b6c2fa8fc358ac8b47a1ba8a8e4df4ecee
4
+ data.tar.gz: dc15778636814c7932b2310f0e11013e3ccec958
5
5
  SHA512:
6
- metadata.gz: cc5f2b338b344a9af3876b09727c6ec104a28913224ad4917474c653eff205acb06bf487398909e3fcce3f265130631de345e7b381cc103723a665695f6470f0
7
- data.tar.gz: b6571de749f6ed59e307572342318cbca852c7093bf6bd690afcd8fb2671620c3fe97f3cf3ec9cf836a647dda05e5aeb7fcb6d4ff66f6ad0d0baf74449a01acf
6
+ metadata.gz: 1877b89fe38a9b45a948a5026baf3b6a5e88a9a0e6a52ed26537c052d01c128e84f49c35a6f9cbfddb1ae330d7ac6be13e81515cd42b2e27f383d8bd81b16db6
7
+ data.tar.gz: e629ef33dfff7f4e73e96394134acd2fc2af8d62f9c5bd8ef4c42d49f95f0ff2cb4c5e2fba464ca97334e73a4e2cc090097aeebca12606391c85cd0e15351c90
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patch_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zzqwdss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: some useful utils and monkey patches
14
14
  email: zzqwdss@163.com
@@ -17,7 +17,6 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/patch_utils.rb
20
- - lib/patch_utils/actions.rb
21
20
  - lib/patch_utils/active_support_encoding.rb
22
21
  - lib/patch_utils/hash.rb
23
22
  - lib/patch_utils/string.rb
@@ -1,82 +0,0 @@
1
- if defined?(ActionController::Caching::Actions)
2
- module ActionController #:nodoc:
3
- module Caching
4
- # With this monkey patch, you can also use action cache as the original one. For more informations, refer to
5
- # actionpack/lib/action_controller/caching/actions.rb in rails3.
6
- # In rails4, action cache is removed from core, refer to https://github.com/rails/actionpack-page_caching,
7
- # and it's original file is
8
- # actionpack-action_caching/lib/action_controller/caching/actions.rb in rails4
9
- #
10
- # The original action cache uses request path without query string as cache key, so "/users/show/1" and "/users/show/2"
11
- # can perform as expected. But "/users/query?name=jody&gender=male" and "/users/query?name=angel&gender=female" will use the same
12
- # cache key, so the latter request will read cache and return the same response.
13
- # So, this new feature is, you can use params as a part of the cache key, by configure them with params.
14
- #
15
- # class UsersController < ApplicationController
16
- # caches_action :query, :cache_path => {:with_params => [:name, :gender]}
17
- # def query
18
- # @user = User.where(:id => params[:id]).first
19
- # end
20
- #
21
- # def update
22
- # user = User.where(:id => params[:id]).first
23
- # expire_action(:controller => "users", :action => "query", :with_params => {:name => user.name, :gender => user.gender})
24
- # user.update_attributes(params)
25
- # end
26
- # end
27
- module Actions
28
- class ActionCachePath
29
- attr_reader :path, :extension
30
-
31
- # If +infer_extension+ is true, the cache path extension is looked up from the request's
32
- # path and format. This is desirable when reading and writing the cache, but not when
33
- # expiring the cache - expire_action should expire the same files regardless of the
34
- # request format.
35
- def initialize(controller, options = {}, infer_extension = true)
36
- with_params = options.extract!(:with_params)
37
- if infer_extension
38
- @extension = controller.params[:format]
39
- options.reverse_merge!(:format => @extension) if options.is_a?(Hash)
40
- end
41
-
42
- path = controller.url_for(options).split(%r{://}).last
43
- @path = normalize!(path)
44
- @path = append_query_string!(@path, controller, with_params[:with_params]) if with_params.present?
45
- end
46
-
47
- private
48
- def append_query_string!(path, controller, with_params)
49
- case with_params
50
- when Array
51
- if controller.env["QUERY_STRING"].blank?
52
- return path
53
- end
54
- _params = Rack::Utils.parse_nested_query(controller.env["QUERY_STRING"]).slice(*with_params.map(&:to_s).sort)
55
- _query_string = Rack::Utils.build_nested_query(_params)
56
- "#{path}?#{URI.parser.unescape(_query_string)}"
57
- when Hash
58
- # Rack::Utils.build_nested_query({:a=>1}) # => "a"
59
- # Rack::Utils.build_nested_query({:a=>'1'}) # => "a=1"
60
- # Rack::Utils.build_nested_query(Rack::Utils.parse_nested_query({:a=>1}.to_param)) # => "a=1"
61
- h = Rack::Utils.parse_nested_query(with_params.to_param)
62
- _query_string = Rack::Utils.build_nested_query(h.slice(*h.keys.sort))
63
- "#{path}?#{URI.parser.unescape(_query_string)}"
64
- when String
65
- if with_params.blank?
66
- return path
67
- end
68
- _ps = Rack::Utils.parse_nested_query(with_params)
69
- _params = _ps.slice(*_ps.keys.sort)
70
- _query_string = Rack::Utils.build_nested_query(_params)
71
- "#{path}?#{URI.parser.unescape(_query_string)}"
72
- else
73
- path
74
- end
75
- end
76
- end
77
- end
78
- end
79
- end
80
- else
81
- # If you are using rails4, you must add actionpack-action_caching to your gem list to use this patch.
82
- end