concord_cacher 0.0.2 → 0.0.3
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/Rakefile +1 -1
- data/concord_cacher.gemspec +2 -2
- data/lib/concord/diy_local_cacher.rb +10 -6
- data/spec/diy_local_cacher_spec.rb +48 -29
- data/spec/helpers/cache_helper.rb +2 -1
- data/spec/java_proxy_cacher_spec.rb +40 -0
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
data/Rakefile
CHANGED
|
@@ -6,7 +6,7 @@ require 'spec/rake/spectask'
|
|
|
6
6
|
require './lib/concord_cacher.rb'
|
|
7
7
|
|
|
8
8
|
require 'echoe'
|
|
9
|
-
Echoe.new('concord_cacher', '0.0.
|
|
9
|
+
Echoe.new('concord_cacher', '0.0.3') do |p|
|
|
10
10
|
p.description = "concord_cacher provides support for locally caching a resource and all referenced resources in multiple different ways. It is intended for using with other Concord Consortium projects and not necessarily for outside projects."
|
|
11
11
|
p.summary = "Support for locally caching a resource and all referenced resources in multiple different ways"
|
|
12
12
|
p.url = "http://github.com/psndcsrv/concord_cacher"
|
data/concord_cacher.gemspec
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = %q{concord_cacher}
|
|
5
|
-
s.version = "0.0.
|
|
5
|
+
s.version = "0.0.3"
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ["Aaron Unger"]
|
|
9
9
|
s.cert_chain = ["/Users/aunger/gem-public_cert.pem"]
|
|
10
|
-
s.date = %q{2010-03-
|
|
10
|
+
s.date = %q{2010-03-26}
|
|
11
11
|
s.description = %q{concord_cacher provides support for locally caching a resource and all referenced resources in multiple different ways. It is intended for using with other Concord Consortium projects and not necessarily for outside projects.}
|
|
12
12
|
s.email = %q{aunger @nospam@ concord.org}
|
|
13
13
|
s.extra_rdoc_files = ["README.textile", "lib/concord_cacher.rb", "lib/concord/cacher.rb", "lib/concord/diy_local_cacher.rb", "lib/concord/java_proxy_cacher.rb"]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class ::Concord::DiyLocalCacher < ::Concord::Cacher
|
|
2
2
|
require 'uri'
|
|
3
3
|
require 'digest/sha1'
|
|
4
|
+
require 'fileutils'
|
|
4
5
|
|
|
5
6
|
def initialize(opts = {})
|
|
6
7
|
raise InvalidArgumentError, "Must include :activity in the options hash." unless opts[:activity]
|
|
@@ -21,11 +22,14 @@ class ::Concord::DiyLocalCacher < ::Concord::Cacher
|
|
|
21
22
|
|
|
22
23
|
def generate_filename(opts = {})
|
|
23
24
|
raise InvalidArgumentError, "Must include :url key in opts" unless opts[:url]
|
|
24
|
-
url
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
raise InvalidArgumentError, ":url value must be an instance of URI" unless opts[:url].kind_of?(::URI)
|
|
26
|
+
uri = opts[:url]
|
|
27
|
+
uri_path = uri.path.split('/')
|
|
28
|
+
uri_path = ["","index.html"] if uri_path.size == 0
|
|
29
|
+
uri_path.unshift("") if uri_path.size == 1
|
|
30
|
+
file_dir = File.join("#{uri.scheme}","#{uri.host}","#{uri.port}",uri_path[0..-2])
|
|
31
|
+
file = uri_path[-1]
|
|
32
|
+
mkdir_p(File.join(@cache_dir,file_dir))
|
|
33
|
+
return File.join(file_dir,file)
|
|
30
34
|
end
|
|
31
35
|
end
|
|
@@ -30,12 +30,31 @@ describe 'DIY Local Cacher' do
|
|
|
30
30
|
@cache += '/'
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
after(:each) do
|
|
34
|
+
rm_rf(@cache)
|
|
35
|
+
end
|
|
36
|
+
|
|
33
37
|
def mockup(file)
|
|
34
38
|
return mock('activity',{:uuid => 'hash', :url => file})
|
|
35
39
|
end
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
def filename_for(url, parent=nil)
|
|
42
|
+
uri = nil
|
|
43
|
+
if parent
|
|
44
|
+
parent_uri = URI.parse(parent)
|
|
45
|
+
parent_uri = URI.parse("file:///").merge(parent_uri) if parent_uri.relative?
|
|
46
|
+
|
|
47
|
+
uri = parent_uri.merge(url)
|
|
48
|
+
else
|
|
49
|
+
uri = URI.parse(url)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
uri_path = uri.path.split('/')
|
|
53
|
+
uri_path = ["","index.html"] if uri_path.size == 0
|
|
54
|
+
uri_path.unshift("") if uri_path.size == 1
|
|
55
|
+
file_dir = File.join("#{uri.scheme}","#{uri.host}","#{uri.port}",uri_path[0..-2])
|
|
56
|
+
file = uri_path[-1]
|
|
57
|
+
return File.join(file_dir,file)
|
|
39
58
|
end
|
|
40
59
|
|
|
41
60
|
describe 'empty otml' do
|
|
@@ -62,8 +81,8 @@ describe 'DIY Local Cacher' do
|
|
|
62
81
|
it 'should cache 2 referenced files' do
|
|
63
82
|
expected_files = []
|
|
64
83
|
expected_files << 'hash.otml' # standard_uri.otml
|
|
65
|
-
expected_files <<
|
|
66
|
-
expected_files <<
|
|
84
|
+
expected_files << filename_for('http://portal.concord.org/images/icons/delete.png')
|
|
85
|
+
expected_files << filename_for('https://mail.google.com/mail/images/2/5/mountains/base/gmail_solid_white.png')
|
|
67
86
|
|
|
68
87
|
cache('standard_uri.otml', :activity => mockup('standard_uri.otml'))
|
|
69
88
|
|
|
@@ -81,8 +100,8 @@ describe 'DIY Local Cacher' do
|
|
|
81
100
|
file_content = File.read(File.join(@cache,'hash.otml'))
|
|
82
101
|
|
|
83
102
|
file_content.should_not match(/http:/)
|
|
84
|
-
file_content.should match(
|
|
85
|
-
file_content.should match(
|
|
103
|
+
file_content.should match(filename_for('http://portal.concord.org/images/icons/delete.png'))
|
|
104
|
+
file_content.should match(filename_for('https://mail.google.com/mail/images/2/5/mountains/base/gmail_solid_white.png'))
|
|
86
105
|
end
|
|
87
106
|
end
|
|
88
107
|
|
|
@@ -90,12 +109,12 @@ describe 'DIY Local Cacher' do
|
|
|
90
109
|
it 'should cache 6 referenced files' do
|
|
91
110
|
expected_files = []
|
|
92
111
|
expected_files << 'hash.otml' # element_reference.otml
|
|
93
|
-
expected_files <<
|
|
94
|
-
expected_files <<
|
|
95
|
-
expected_files <<
|
|
96
|
-
expected_files <<
|
|
97
|
-
expected_files <<
|
|
98
|
-
expected_files <<
|
|
112
|
+
expected_files << filename_for('http://loops.diy.concord.org/')
|
|
113
|
+
expected_files << filename_for('http://portal.concord.org/images/icons/chart_bar.png')
|
|
114
|
+
expected_files << filename_for('http://portal.concord.org/images/icons/chart_pie.png')
|
|
115
|
+
expected_files << filename_for('resources/text.txt', File.join(SPEC_ROOT,'data','element_reference.otml'))
|
|
116
|
+
expected_files << filename_for('resources/delete.png', File.join(SPEC_ROOT,'data','element_reference.otml'))
|
|
117
|
+
expected_files << filename_for('resources/chart_line.png', File.join(SPEC_ROOT,'data','element_reference.otml'))
|
|
99
118
|
|
|
100
119
|
cache('element_reference.otml', :activity => mockup('element_reference.otml'))
|
|
101
120
|
|
|
@@ -117,9 +136,9 @@ describe 'DIY Local Cacher' do
|
|
|
117
136
|
|
|
118
137
|
unexpected_urls.each do |url|
|
|
119
138
|
if url =~ /^http/
|
|
120
|
-
expected_urls <<
|
|
139
|
+
expected_urls << filename_for(url)
|
|
121
140
|
else
|
|
122
|
-
expected_urls <<
|
|
141
|
+
expected_urls << filename_for(url, File.join(SPEC_ROOT,'data','element_reference.otml'))
|
|
123
142
|
end
|
|
124
143
|
end
|
|
125
144
|
|
|
@@ -128,7 +147,7 @@ describe 'DIY Local Cacher' do
|
|
|
128
147
|
file_content = File.read(File.join(@cache,'hash.otml'))
|
|
129
148
|
|
|
130
149
|
unexpected_urls.each do |url|
|
|
131
|
-
file_content.should_not match(Regexp.new(url))
|
|
150
|
+
file_content.should_not match(Regexp.new('"'+url))
|
|
132
151
|
end
|
|
133
152
|
|
|
134
153
|
expected_urls.each do |url|
|
|
@@ -141,10 +160,10 @@ describe 'DIY Local Cacher' do
|
|
|
141
160
|
it 'should cache 4 referenced files in otml files' do
|
|
142
161
|
expected_files = []
|
|
143
162
|
expected_files << 'hash.otml' # recursion.otml
|
|
144
|
-
expected_files <<
|
|
145
|
-
expected_files <<
|
|
146
|
-
expected_files <<
|
|
147
|
-
expected_files <<
|
|
163
|
+
expected_files << filename_for('resources/recurse1.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
164
|
+
expected_files << filename_for('resources/delete.png', File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
165
|
+
expected_files << filename_for('resources/recurse2.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
166
|
+
expected_files << filename_for('resources/chart_line.png', File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
148
167
|
|
|
149
168
|
cache('recursion.otml', :activity => mockup('recursion.otml'))
|
|
150
169
|
|
|
@@ -155,7 +174,7 @@ describe 'DIY Local Cacher' do
|
|
|
155
174
|
end
|
|
156
175
|
|
|
157
176
|
it 'should rewrite urls in first level recursion otml' do
|
|
158
|
-
recurse_otml =
|
|
177
|
+
recurse_otml = filename_for('resources/recurse1.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
159
178
|
|
|
160
179
|
expected_urls = []
|
|
161
180
|
unexpected_urls = []
|
|
@@ -164,7 +183,7 @@ describe 'DIY Local Cacher' do
|
|
|
164
183
|
unexpected_urls << File.join('resources','delete.png')
|
|
165
184
|
|
|
166
185
|
unexpected_urls.each do |url|
|
|
167
|
-
expected_urls <<
|
|
186
|
+
expected_urls << filename_for(url, File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
168
187
|
end
|
|
169
188
|
|
|
170
189
|
cache('recursion.otml', :activity => mockup('recursion.otml'))
|
|
@@ -172,7 +191,7 @@ describe 'DIY Local Cacher' do
|
|
|
172
191
|
file_content = File.read(File.join(@cache,recurse_otml))
|
|
173
192
|
|
|
174
193
|
unexpected_urls.each do |url|
|
|
175
|
-
file_content.should_not match(Regexp.new(url))
|
|
194
|
+
file_content.should_not match(Regexp.new('"'+url))
|
|
176
195
|
end
|
|
177
196
|
|
|
178
197
|
expected_urls.each do |url|
|
|
@@ -181,7 +200,7 @@ describe 'DIY Local Cacher' do
|
|
|
181
200
|
end
|
|
182
201
|
|
|
183
202
|
it 'should rewrite urls in second level recursion otml' do
|
|
184
|
-
recurse_otml =
|
|
203
|
+
recurse_otml = recurse_otml = filename_for('resources/recurse2.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
185
204
|
|
|
186
205
|
expected_urls = []
|
|
187
206
|
unexpected_urls = []
|
|
@@ -189,7 +208,7 @@ describe 'DIY Local Cacher' do
|
|
|
189
208
|
unexpected_urls << File.join('resources','chart_line.png')
|
|
190
209
|
|
|
191
210
|
unexpected_urls.each do |url|
|
|
192
|
-
expected_urls <<
|
|
211
|
+
expected_urls << filename_for(url, File.join(SPEC_ROOT,'data','recursion.otml'))
|
|
193
212
|
end
|
|
194
213
|
|
|
195
214
|
cache('recursion.otml', :activity => mockup('recursion.otml'))
|
|
@@ -197,7 +216,7 @@ describe 'DIY Local Cacher' do
|
|
|
197
216
|
file_content = File.read(File.join(@cache,recurse_otml))
|
|
198
217
|
|
|
199
218
|
unexpected_urls.each do |url|
|
|
200
|
-
file_content.should_not match(Regexp.new(url))
|
|
219
|
+
file_content.should_not match(Regexp.new('"'+url))
|
|
201
220
|
end
|
|
202
221
|
|
|
203
222
|
expected_urls.each do |url|
|
|
@@ -208,10 +227,10 @@ describe 'DIY Local Cacher' do
|
|
|
208
227
|
it 'should not get stuck when handling circular loops' do
|
|
209
228
|
expected_files = []
|
|
210
229
|
expected_files << 'hash.otml' # recursion.otml
|
|
211
|
-
expected_files <<
|
|
212
|
-
expected_files <<
|
|
213
|
-
expected_files <<
|
|
214
|
-
expected_files <<
|
|
230
|
+
expected_files << filename_for('resources/loop1.otml', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
|
|
231
|
+
expected_files << filename_for('resources/delete.png', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
|
|
232
|
+
expected_files << filename_for('resources/loop2.otml', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
|
|
233
|
+
expected_files << filename_for('resources/chart_line.png', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
|
|
215
234
|
|
|
216
235
|
lambda {
|
|
217
236
|
cache('recursive_loop.otml', :activity => mockup('recursive_loop.otml'))
|
|
@@ -8,6 +8,7 @@ module CacheHelper
|
|
|
8
8
|
def exists?(file)
|
|
9
9
|
f = File.join(@cache,file)
|
|
10
10
|
File.should be_exists(f)
|
|
11
|
+
File.should be_file(f)
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def does_not_exist?(file)
|
|
@@ -16,6 +17,6 @@ module CacheHelper
|
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def cache_size
|
|
19
|
-
Dir.glob(@cache + "
|
|
20
|
+
Dir.glob(@cache + "/**/*").select{|f| File.file?(f) }.size
|
|
20
21
|
end
|
|
21
22
|
end
|
|
@@ -38,6 +38,7 @@ describe 'Java Proxy Cacher' do
|
|
|
38
38
|
describe 'empty otml' do
|
|
39
39
|
it 'should create a url map xml file' do
|
|
40
40
|
cache('empty.otml')
|
|
41
|
+
cache_size.should == 3
|
|
41
42
|
exists?('url_map.xml')
|
|
42
43
|
end
|
|
43
44
|
|
|
@@ -45,6 +46,7 @@ describe 'Java Proxy Cacher' do
|
|
|
45
46
|
url = File.join(SPEC_ROOT,'data','empty.otml')
|
|
46
47
|
expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
|
|
47
48
|
cache('empty.otml')
|
|
49
|
+
cache_size.should == 3
|
|
48
50
|
exists?(expected_filename)
|
|
49
51
|
end
|
|
50
52
|
|
|
@@ -52,10 +54,48 @@ describe 'Java Proxy Cacher' do
|
|
|
52
54
|
url = File.join(SPEC_ROOT,'data','empty.otml')
|
|
53
55
|
expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
|
|
54
56
|
cache('empty.otml')
|
|
57
|
+
cache_size.should == 3
|
|
55
58
|
exists?("#{expected_filename}.hdrs")
|
|
56
59
|
end
|
|
57
60
|
end
|
|
58
61
|
|
|
62
|
+
describe 'error handling' do
|
|
63
|
+
it 'should handle a bad url gracefully' do
|
|
64
|
+
url = File.join(SPEC_ROOT,'data','bad_url.otml')
|
|
65
|
+
expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
|
|
66
|
+
|
|
67
|
+
lambda {
|
|
68
|
+
cache('bad_url.otml')
|
|
69
|
+
}.should_not raise_error
|
|
70
|
+
|
|
71
|
+
cache_size.should == 3
|
|
72
|
+
|
|
73
|
+
exists?(expected_filename)
|
|
74
|
+
does_not_exist?('8f0ebcb45d7ba71a541d4781329f4a6900c7ee65') # http://portal.concord.org/images/icons/delete.png
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should handle an empty url gracefully' do
|
|
78
|
+
url = File.join(SPEC_ROOT,'data','empty_url.otml')
|
|
79
|
+
expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
|
|
80
|
+
|
|
81
|
+
lambda {
|
|
82
|
+
cache('empty_url.otml')
|
|
83
|
+
}.should_not raise_error
|
|
84
|
+
|
|
85
|
+
cache_size.should == 3
|
|
86
|
+
|
|
87
|
+
exists?(expected_filename)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'should handle an empty root url gracefully' do
|
|
91
|
+
lambda {
|
|
92
|
+
cache('')
|
|
93
|
+
}.should_not raise_error
|
|
94
|
+
|
|
95
|
+
cache_size.should == 1
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
59
99
|
describe 'standard uri syntax' do
|
|
60
100
|
it 'should cache 2 referenced files' do
|
|
61
101
|
expected_files = []
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 0.0.
|
|
8
|
+
- 3
|
|
9
|
+
version: 0.0.3
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Aaron Unger
|
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
|
35
35
|
8kT2T2VF
|
|
36
36
|
-----END CERTIFICATE-----
|
|
37
37
|
|
|
38
|
-
date: 2010-03-
|
|
38
|
+
date: 2010-03-26 00:00:00 -04:00
|
|
39
39
|
default_executable:
|
|
40
40
|
dependencies: []
|
|
41
41
|
|
metadata.gz.sig
CHANGED
|
Binary file
|