rack-cachely 0.1.0 → 0.2.0

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.
@@ -5,10 +5,17 @@ module Rack
5
5
  attr_accessor :options
6
6
 
7
7
  def initialize(options = {})
8
- self.options = options
8
+ self.options = {ignore_query_params: []}
9
+ options.each do |key, value|
10
+ self.send("#{key}=", value)
11
+ end
9
12
  self.options[:cachely_url] = "#{(self.options[:cachely_url] ||= ENV["CACHELY_URL"])}/v1/cache"
10
13
  end
11
14
 
15
+ def ignore_query_params=(*args)
16
+ self.options[:ignore_query_params] = [args].flatten.map {|x| x.downcase}
17
+ end
18
+
12
19
  def method_missing(sym, *args, &block)
13
20
  if /(.+)=$/.match(sym.to_s)
14
21
  self.options[$1.to_sym] = args[0]
@@ -7,7 +7,7 @@ module Rack
7
7
  end
8
8
 
9
9
  def request
10
- @request ||= Rack::Request.new(@env.dup.freeze)
10
+ @request ||= Rack::Request.new(@env.dup)
11
11
  end
12
12
 
13
13
  def call(env)
@@ -31,7 +31,7 @@ module Rack
31
31
  else
32
32
  @env['rack-cachely.perform_caching'].to_s == 'true'
33
33
  end
34
- config && request.request_method == 'GET'
34
+ config && request.request_method == 'GET' && !request.params["no-cachely"]
35
35
  end
36
36
 
37
37
  def is_cacheable?(results)
@@ -44,11 +44,10 @@ module Rack
44
44
  def query_string
45
45
  return nil if @request.query_string.nil?
46
46
 
47
- @request.query_string.split(/[&;] */n).
48
- map { |p| unescape(p).split('=', 2) }.
49
- sort.
50
- map { |k,v| "#{escape(k)}=#{escape(v)}" }.
51
- join('&')
47
+ query = @request.query_string.split(/[&;] */n).map { |p| unescape(p).split('=', 2) }.sort
48
+ query = query.reject{|k,v| Rack::Cachely.config.ignore_query_params.include?(k)}.map{ |k,v| "#{escape(k)}=#{escape(v)}" }
49
+
50
+ query.join('&')
52
51
  end
53
52
  end
54
53
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Cachely
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -6,10 +6,15 @@ describe Rack::Cachely::Key do
6
6
 
7
7
  describe "generate" do
8
8
 
9
- let(:request) { double(scheme: "http", host: "example.com", port: 80, script_name: "/foo", path_info: "/bar", query_string: "b=B&a=A") }
9
+ let(:request) { double(scheme: "http", host: "example.com", port: 80, script_name: "/foo", path_info: "/bar", query_string: "b=B&a=A&d=D&c=C") }
10
10
 
11
11
  it "returns a uniformed url" do
12
- key.to_s.should eql("http://example.com/foo/bar?a=A&b=B")
12
+ key.to_s.should eql("http://example.com/foo/bar?a=A&b=B&c=C&d=D")
13
+ end
14
+
15
+ it "will ignore certain query params" do
16
+ Rack::Cachely.config.ignore_query_params = ["A", "c"]
17
+ key.to_s.should eql("http://example.com/foo/bar?b=B&d=D")
13
18
  end
14
19
 
15
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cachely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-17 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack