rack-gist 1.0.7 → 1.1.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.
- data/VERSION +1 -1
- data/lib/rack/gist.rb +15 -10
- data/rack-gist.gemspec +2 -2
- data/spec/rack-gist_spec.rb +42 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/rack/gist.rb
CHANGED
@@ -6,7 +6,9 @@ module Rack
|
|
6
6
|
def initialize(app, options = {})
|
7
7
|
@app = app
|
8
8
|
@options = {
|
9
|
-
:jquery => true
|
9
|
+
:jquery => true,
|
10
|
+
:cache_time => 3600,
|
11
|
+
:http_cache_time => 3600
|
10
12
|
}.merge(options)
|
11
13
|
end
|
12
14
|
|
@@ -55,15 +57,18 @@ module Rack
|
|
55
57
|
def serve_gist(env)
|
56
58
|
gist_id, file = path(env).match(regex)[1,2]
|
57
59
|
cache = @options[:cache]
|
58
|
-
gist = (cache ? cache.fetch(cache_key(gist_id, file), :expires_in =>
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
gist = (cache ? cache.fetch(cache_key(gist_id, file), :expires_in => @options[:cache_time]) { get_gist(gist_id, file) } : get_gist(gist_id, file)).to_s
|
61
|
+
headers = {
|
62
|
+
'Content-Type' => 'application/javascript',
|
63
|
+
'Content-Length' => Rack::Utils.bytesize(gist).to_s,
|
64
|
+
'Vary' => 'Accept-Encoding'
|
65
|
+
}
|
66
|
+
|
67
|
+
if @options[:http_cache_time]
|
68
|
+
headers['Cache-Control'] = "public, must-revalidate, max-age=#{@options[:http_cache_time]}"
|
69
|
+
end
|
70
|
+
|
71
|
+
[200, headers, [gist]]
|
67
72
|
end
|
68
73
|
|
69
74
|
def get_gist(gist_id, file)
|
data/rack-gist.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rack-gist}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Huckstep"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-02}
|
13
13
|
s.description = %q{Load gists in the background. KTHXBYE!}
|
14
14
|
s.email = %q{darkhelmet@darkhelmetlive.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/rack-gist_spec.rb
CHANGED
@@ -143,7 +143,24 @@ describe "Rack::Gist" do
|
|
143
143
|
headers['Content-Type'].should == 'application/javascript'
|
144
144
|
|
145
145
|
RestClient.should_not_receive(:get)
|
146
|
-
cache.should_receive(:fetch).once.with("rack-gist:#{@gist_id}:example.pig", :expires_in => 3600).and_return(body) #
|
146
|
+
cache.should_receive(:fetch).once.with("rack-gist:#{@gist_id}:example.pig", :expires_in => 3600).and_return(body) # 1.hour
|
147
|
+
|
148
|
+
status, headers, body2 = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
149
|
+
status.should == 200
|
150
|
+
headers['Content-Type'].should == 'application/javascript'
|
151
|
+
body.should == body2
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should cache things for a different time if given cache_time' do
|
156
|
+
cache = ActiveSupport::Cache::MemoryStore.new
|
157
|
+
middleware(:cache => cache, :cache_time => 60).tap do |a|
|
158
|
+
status, headers, body = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
159
|
+
status.should == 200
|
160
|
+
headers['Content-Type'].should == 'application/javascript'
|
161
|
+
|
162
|
+
RestClient.should_not_receive(:get)
|
163
|
+
cache.should_receive(:fetch).once.with("rack-gist:#{@gist_id}:example.pig", :expires_in => 60).and_return(body) # 1.hour
|
147
164
|
|
148
165
|
status, headers, body2 = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
149
166
|
status.should == 200
|
@@ -158,4 +175,28 @@ describe "Rack::Gist" do
|
|
158
175
|
status.should == 404
|
159
176
|
end
|
160
177
|
end
|
178
|
+
|
179
|
+
it 'should set http caching headers by default' do
|
180
|
+
middleware.tap do |a|
|
181
|
+
status, headers, body = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
182
|
+
headers['Vary'].should == 'Accept-Encoding'
|
183
|
+
headers['Cache-Control'].should == 'public, must-revalidate, max-age=3600' # 1.hour
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should be able to configure cache time' do
|
188
|
+
middleware(:http_cache_time => 60).tap do |a|
|
189
|
+
status, headers, body = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
190
|
+
headers['Vary'].should == 'Accept-Encoding'
|
191
|
+
headers['Cache-Control'].should == 'public, must-revalidate, max-age=60' # 1.hour
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'should be able to disable caching by setting http_cache_time to nil' do
|
196
|
+
middleware(:http_cache_time => nil).tap do |a|
|
197
|
+
status, headers, body = a.call(mock_env("/gist.github.com/#{@gist_id}/example.pig.js"))
|
198
|
+
headers['Vary'].should == 'Accept-Encoding'
|
199
|
+
headers['Cache-Control'].should be_nil
|
200
|
+
end
|
201
|
+
end
|
161
202
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-gist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.7
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Huckstep
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-02 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|