rack-cachely 0.4.0 → 0.4.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f4080bb9c2d7996d66615deb889c894bbb4899d
4
- data.tar.gz: 97b741a1f1b6c746c417066cb8191465f647af0f
3
+ metadata.gz: d5cc375109389743f021cf1f7fb371099ea0131a
4
+ data.tar.gz: c5871bb7b78afb9d243a5ca315d6dc1cba2a25a0
5
5
  SHA512:
6
- metadata.gz: 1e95627d21f37a878f4017c57647fb90fc6c51f185631f482d5b3f048562b635bc16e5b77273248d4376991217e5213c079ecae71fb88829e8ee2d4b02cbe4bc
7
- data.tar.gz: 9185062d94498de7efa4003205ebd66d0cac8974661f3e94eaabe3e569cc0f59af027c85a36003a8e769585c8ee0bbd6624884fb92b58ecef95cfe50b7aac745
6
+ metadata.gz: 8e5d8d6a5106081cb2de26431de63c3fc689471bd6e9075fec3be1c4c581b8fa836cc8aa381310cae89eecef121dc24605b9557cb19b70d437b14456f634245b
7
+ data.tar.gz: 04459c6d33d29e5e9c19fcd8e4bd969427c27c3c07d4f68034228f669773ff6f1abe94496728c898ee648194921eac77968db9995fc5004ea4a21cc179c283ca
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-cachely (0.4.0)
4
+ rack-cachely (0.4.1)
5
5
  rack
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -18,9 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- **CACHELY IS CURRENTLY IN PRIVATE BETA.**
22
-
23
- If you would like to join the private beta, please email [mark+cachely@meta42.com](mailto:mark+cachely@meta42.com)
21
+ Cachely is currently available only as a Heroku Add-on.
24
22
 
25
23
  ### Rails 3.x
26
24
 
@@ -87,4 +85,5 @@ Rack::Cachely::Store.delete("users/\d+")
87
85
  ## Contributors
88
86
 
89
87
  * Mark Bates
88
+ * Sam Beam
90
89
  * Tim Raymond
@@ -9,7 +9,17 @@ module Rack
9
9
  options.each do |key, value|
10
10
  self.send("#{key}=", value)
11
11
  end
12
- self.options[:cachely_url] = "#{(self.options[:cachely_url] ||= ENV["CACHELY_URL"])}/v1/cache"
12
+
13
+ url = options[:cachely_url] || ENV["CACHELY_URL"]
14
+
15
+ if !url || (url.respond_to?(:empty?) && url.empty?)
16
+ self.logger.warn("Cachely: config incomplete (cachely_url is missing), disabling cachley.")
17
+ self.options[:enabled] = false
18
+ else
19
+ url = "#{url}/v1/cache"
20
+ self.options[:enabled] = true
21
+ end
22
+ self.cachely_url = url
13
23
  end
14
24
 
15
25
  def ignore_query_params=(*args)
@@ -38,7 +38,7 @@ module Rack
38
38
  else
39
39
  @env['rack-cachely.perform_caching'].to_s == 'true'
40
40
  end
41
- perform_caching && request.request_method == 'GET' && !request.params["no-cachely"]
41
+ perform_caching && config.enabled && request.request_method == 'GET' && !request.params["no-cachely"]
42
42
  end
43
43
 
44
44
  def is_cacheable?(results)
@@ -64,4 +64,4 @@ module Rack
64
64
  end
65
65
 
66
66
  end
67
- end
67
+ end
@@ -70,8 +70,8 @@ module Rack
70
70
 
71
71
  def remote(&block)
72
72
  begin
73
- Timeout::timeout(config.timeout, &block)
74
- rescue Timeout::Error, Errno::ECONNREFUSED => e
73
+ ::Timeout::timeout(config.timeout, &block)
74
+ rescue ::Timeout::Error, Errno::ECONNREFUSED => e
75
75
  # raise e
76
76
  logger.error(e)
77
77
  end
@@ -87,4 +87,4 @@ module Rack
87
87
 
88
88
  end
89
89
  end
90
- end
90
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Cachely
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -21,4 +21,37 @@ describe Rack::Cachely::Config do
21
21
 
22
22
  end
23
23
 
24
- end
24
+
25
+ describe "initializer" do
26
+
27
+ it "sets cachely_url from ENV" do
28
+ config.cachely_url.should == "#{ENV['CACHELY_URL']}/v1/cache"
29
+ end
30
+
31
+ it "sets enabled" do
32
+ config.enabled.should == true
33
+ end
34
+
35
+ context "with no ENV['CACHELY_URL']" do
36
+
37
+ before do
38
+ @old_env = ENV.delete('CACHELY_URL')
39
+ @logger = mock
40
+ Rack::Cachely::Config.any_instance.stub(:logger).and_return @logger
41
+ end
42
+
43
+ after do
44
+ ENV['CACHELY_URL'] = @old_env
45
+ end
46
+
47
+ it "warns and disables if there is no cachely_url" do
48
+ @logger.should_receive(:warn)
49
+ config.enabled.should == false
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+
57
+ end
@@ -2,6 +2,53 @@ require 'spec_helper'
2
2
 
3
3
  describe Rack::Cachely::Context do
4
4
 
5
-
5
+ describe 'call' do
6
6
 
7
- end
7
+ let(:app) { mock }
8
+ let(:context) { Rack::Cachely::Context.new(app) }
9
+
10
+ context 'when cachely is disabled in config' do
11
+ before do
12
+ Rack::Cachely.config.enabled = false
13
+ end
14
+
15
+ it 'invokes the app' do
16
+ app.should_receive(:call)
17
+ context.call({})
18
+ end
19
+
20
+ end
21
+
22
+ context 'with cachely enabled in config' do
23
+ before do
24
+ Rack::Cachely.config.enabled = true
25
+ @env = { 'rack-cachely.perform_caching' => true }
26
+ Rack::Cachely::Store.stub(get: true)
27
+ end
28
+
29
+ context 'without no-cachely param' do
30
+ before do
31
+ context.stub(:request => mock(:request_method => 'GET', :params => {}))
32
+ end
33
+
34
+ it 'does not invoke the app' do
35
+ app.should_not_receive(:call)
36
+ context.call(@env)
37
+ end
38
+ end
39
+
40
+ context 'with no-cachely param' do
41
+ before do
42
+ context.stub(:request => mock(:request_method => 'GET', :params => {'no-cachely' => true}))
43
+ end
44
+
45
+ it 'invokes the app' do
46
+ app.should_receive(:call)
47
+ context.call(@env)
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -35,7 +35,7 @@ describe Rack::Cachely::Store do
35
35
  store.get(key).should be_nil
36
36
  }.to_not raise_error(Timeout::Error)
37
37
  end
38
-
38
+
39
39
  end
40
40
 
41
41
  describe "post" do
@@ -82,4 +82,4 @@ describe Rack::Cachely::Store do
82
82
 
83
83
  end
84
84
 
85
- end
85
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cachely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Bates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-31 00:00:00.000000000 Z
11
+ date: 2013-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -78,3 +78,4 @@ test_files:
78
78
  - spec/rack-cachely/key_spec.rb
79
79
  - spec/rack-cachely/store_spec.rb
80
80
  - spec/spec_helper.rb
81
+ has_rdoc: