concord_cacher 0.1.0 → 0.1.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.
data.tar.gz.sig CHANGED
Binary file
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.1.0') do |p|
9
+ Echoe.new('concord_cacher', '0.1.1') 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"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{concord_cacher}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
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"]
@@ -20,28 +20,25 @@ class ::Concord::Cacher
20
20
  end
21
21
 
22
22
  def calculate_main_file_absolute_url
23
- orig_uri = @main_resource.uri
23
+ new_uri = @main_resource.uri
24
24
  codebase = ''
25
- if ((orig_uri.kind_of?(URI::HTTP) || orig_uri.kind_of?(URI::HTTPS)) && orig_uri.absolute?)
26
- @main_resource.uri = orig_uri
27
- else
28
- # this probably references something on the local fs. we need to extract the document's codebase, if there is ony
29
- if @main_resource.content =~ /<otrunk[^>]+codebase[ ]?=[ ]?['"]([^'"]+)/
30
- codebase = "#{$1}"
31
- @main_resource.content.sub!(/codebase[ ]?=[ ]?['"][^'"]+['"]/,"")
32
- codebase.sub!(/\/$/,'')
33
- codebase = "#{codebase}/#{@main_resource.remote_filename}" unless codebase =~ /otml$/
34
- @main_resource.uri = URI.parse(codebase)
35
- else
36
- @main_resource.uri = orig_uri
37
- end
25
+
26
+ if _needs_codebase?(new_uri) && @main_resource.has_codebase?
27
+ # this probably references something on the local fs. we need to extract the document's codebase, if there is ony
28
+ codebase = "#{$1}"
29
+ @main_resource.remove_codebase
30
+ codebase.sub!(/\/$/,'')
31
+ codebase = "#{codebase}/#{@main_resource.remote_filename}" unless codebase =~ /otml$/
32
+ new_uri = URI.parse(codebase)
38
33
  end
39
34
 
40
- if @main_resource.uri.relative?
35
+ if new_uri.relative?
41
36
  # we need the main URI to be absolute so that we can use it to resolve references
42
37
  file_root = URI.parse("file:///")
43
- @main_resource.uri = file_root.merge(@main_resource.uri)
38
+ new_uri = file_root.merge(new_uri)
44
39
  end
40
+
41
+ @main_resource.uri = new_uri
45
42
  end
46
43
 
47
44
  def cache
@@ -57,12 +54,19 @@ class ::Concord::Cacher
57
54
  end
58
55
 
59
56
  def print_errors
60
- puts "\nThere were #{@errors.length} artifacts with errors.\n"
61
- ::Concord::Resource.errors.each do |k,v|
62
- puts "In #{k}:"
63
- v.uniq.each do |e|
64
- puts " #{e}"
57
+ all_errors = ::Concord::Resource.errors
58
+ puts "\nThere were #{all_errors.length} artifacts with errors.\n"
59
+ all_errors.each do |url,errors|
60
+ puts "In #{url}:"
61
+ errors.uniq.each do |error|
62
+ puts " #{error}"
65
63
  end
66
64
  end
67
65
  end
66
+
67
+ private
68
+
69
+ def _needs_codebase?(uri)
70
+ return ! ((uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)) && uri.absolute?)
71
+ end
68
72
  end
@@ -10,14 +10,13 @@ require 'fileutils'
10
10
 
11
11
  include FileUtils
12
12
 
13
- SPEC_ROOT = File.expand_path(File.dirname(__FILE__))
14
-
15
13
  describe 'DIY Local Cacher' do
16
14
  include CacheHelper
17
15
 
18
16
  before(:each) do
19
17
  @klass = Concord::DiyLocalCacher
20
- @cache = File.join(SPEC_ROOT, '..', 'tmp','diy_local')
18
+ @spec_root = File.expand_path(File.dirname(__FILE__))
19
+ @cache = File.join(@spec_root, '..', 'tmp','diy_local')
21
20
  mkdir_p(@cache)
22
21
  @cache += '/'
23
22
  end
@@ -62,7 +61,7 @@ describe 'DIY Local Cacher' do
62
61
  end
63
62
 
64
63
  it 'should not create a cached header of the original url' do
65
- url = File.join(SPEC_ROOT,'data','empty.otml')
64
+ url = File.join(@spec_root,'data','empty.otml')
66
65
  expected_filename = 'hash.otml'
67
66
  cache('empty.otml', :activity => mockup('empty.otml'))
68
67
  does_not_exist?("#{expected_filename}.hdrs")
@@ -111,9 +110,9 @@ describe 'DIY Local Cacher' do
111
110
  expected_files << filename_for('http://www.concord.org/~aunger/')
112
111
  expected_files << filename_for('http://portal.concord.org/images/icons/chart_bar.png')
113
112
  expected_files << filename_for('http://portal.concord.org/images/icons/chart_pie.png')
114
- expected_files << filename_for('resources/text.txt', File.join(SPEC_ROOT,'data','element_reference.otml'))
115
- expected_files << filename_for('resources/delete.png', File.join(SPEC_ROOT,'data','element_reference.otml'))
116
- expected_files << filename_for('resources/chart_line.png', File.join(SPEC_ROOT,'data','element_reference.otml'))
113
+ expected_files << filename_for('resources/text.txt', File.join(@spec_root,'data','element_reference.otml'))
114
+ expected_files << filename_for('resources/delete.png', File.join(@spec_root,'data','element_reference.otml'))
115
+ expected_files << filename_for('resources/chart_line.png', File.join(@spec_root,'data','element_reference.otml'))
117
116
 
118
117
  cache('element_reference.otml', :activity => mockup('element_reference.otml'))
119
118
 
@@ -137,7 +136,7 @@ describe 'DIY Local Cacher' do
137
136
  if url =~ /^http/
138
137
  expected_urls << filename_for(url)
139
138
  else
140
- expected_urls << filename_for(url, File.join(SPEC_ROOT,'data','element_reference.otml'))
139
+ expected_urls << filename_for(url, File.join(@spec_root,'data','element_reference.otml'))
141
140
  end
142
141
  end
143
142
 
@@ -159,10 +158,10 @@ describe 'DIY Local Cacher' do
159
158
  it 'should cache 4 referenced files in otml files' do
160
159
  expected_files = []
161
160
  expected_files << 'hash.otml' # recursion.otml
162
- expected_files << filename_for('resources/recurse1.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
163
- expected_files << filename_for('resources/delete.png', File.join(SPEC_ROOT,'data','recursion.otml'))
164
- expected_files << filename_for('resources/recurse2.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
165
- expected_files << filename_for('resources/chart_line.png', File.join(SPEC_ROOT,'data','recursion.otml'))
161
+ expected_files << filename_for('resources/recurse1.otml', File.join(@spec_root,'data','recursion.otml'))
162
+ expected_files << filename_for('resources/delete.png', File.join(@spec_root,'data','recursion.otml'))
163
+ expected_files << filename_for('resources/recurse2.otml', File.join(@spec_root,'data','recursion.otml'))
164
+ expected_files << filename_for('resources/chart_line.png', File.join(@spec_root,'data','recursion.otml'))
166
165
 
167
166
  cache('recursion.otml', :activity => mockup('recursion.otml'))
168
167
 
@@ -173,7 +172,7 @@ describe 'DIY Local Cacher' do
173
172
  end
174
173
 
175
174
  it 'should rewrite urls in first level recursion otml' do
176
- recurse_otml = filename_for('resources/recurse1.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
175
+ recurse_otml = filename_for('resources/recurse1.otml', File.join(@spec_root,'data','recursion.otml'))
177
176
 
178
177
  expected_urls = []
179
178
  unexpected_urls = []
@@ -182,7 +181,7 @@ describe 'DIY Local Cacher' do
182
181
  unexpected_urls << File.join('resources','delete.png')
183
182
 
184
183
  unexpected_urls.each do |url|
185
- expected_urls << filename_for(url, File.join(SPEC_ROOT,'data','recursion.otml'))
184
+ expected_urls << filename_for(url, File.join(@spec_root,'data','recursion.otml'))
186
185
  end
187
186
 
188
187
  cache('recursion.otml', :activity => mockup('recursion.otml'))
@@ -199,7 +198,7 @@ describe 'DIY Local Cacher' do
199
198
  end
200
199
 
201
200
  it 'should rewrite urls in second level recursion otml' do
202
- recurse_otml = recurse_otml = filename_for('resources/recurse2.otml', File.join(SPEC_ROOT,'data','recursion.otml'))
201
+ recurse_otml = recurse_otml = filename_for('resources/recurse2.otml', File.join(@spec_root,'data','recursion.otml'))
203
202
 
204
203
  expected_urls = []
205
204
  unexpected_urls = []
@@ -207,7 +206,7 @@ describe 'DIY Local Cacher' do
207
206
  unexpected_urls << File.join('resources','chart_line.png')
208
207
 
209
208
  unexpected_urls.each do |url|
210
- expected_urls << filename_for(url, File.join(SPEC_ROOT,'data','recursion.otml'))
209
+ expected_urls << filename_for(url, File.join(@spec_root,'data','recursion.otml'))
211
210
  end
212
211
 
213
212
  cache('recursion.otml', :activity => mockup('recursion.otml'))
@@ -226,10 +225,10 @@ describe 'DIY Local Cacher' do
226
225
  it 'should not get stuck when handling circular loops' do
227
226
  expected_files = []
228
227
  expected_files << 'hash.otml' # recursion.otml
229
- expected_files << filename_for('resources/loop1.otml', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
230
- expected_files << filename_for('resources/delete.png', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
231
- expected_files << filename_for('resources/loop2.otml', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
232
- expected_files << filename_for('resources/chart_line.png', File.join(SPEC_ROOT,'data','recursive_loop.otml'))
228
+ expected_files << filename_for('resources/loop1.otml', File.join(@spec_root,'data','recursive_loop.otml'))
229
+ expected_files << filename_for('resources/delete.png', File.join(@spec_root,'data','recursive_loop.otml'))
230
+ expected_files << filename_for('resources/loop2.otml', File.join(@spec_root,'data','recursive_loop.otml'))
231
+ expected_files << filename_for('resources/chart_line.png', File.join(@spec_root,'data','recursive_loop.otml'))
233
232
 
234
233
  lambda {
235
234
  cache('recursive_loop.otml', :activity => mockup('recursive_loop.otml'))
@@ -256,7 +255,7 @@ describe 'DIY Local Cacher' do
256
255
 
257
256
  it 'should download relative referenced nlogo files' do
258
257
  expected_files = []
259
- expected_files << filename_for('resources/nlogo/SpaceRescue.Practice1.nlogo', File.join(SPEC_ROOT,'data','nlogo_relative.otml'))
258
+ expected_files << filename_for('resources/nlogo/SpaceRescue.Practice1.nlogo', File.join(@spec_root,'data','nlogo_relative.otml'))
260
259
 
261
260
  cache('nlogo_relative.otml', :activity => mockup('nlogo_relative.otml'))
262
261
 
@@ -282,7 +281,7 @@ describe 'DIY Local Cacher' do
282
281
 
283
282
  it 'should download relative referenced cml files' do
284
283
  expected_files = []
285
- expected_files << filename_for('resources/statesofmatter/statesOfMatterPage1.cml', File.join(SPEC_ROOT,'data','mw_model_relative.otml'))
284
+ expected_files << filename_for('resources/statesofmatter/statesOfMatterPage1.cml', File.join(@spec_root,'data','mw_model_relative.otml'))
286
285
 
287
286
  cache('mw_model_relative.otml', :activity => mockup('mw_model_relative.otml'))
288
287
 
@@ -308,7 +307,7 @@ describe 'DIY Local Cacher' do
308
307
 
309
308
  describe 'never cache' do
310
309
  it 'should always skip some references' do
311
- url = File.join(SPEC_ROOT,'data','always_skip.otml')
310
+ url = File.join(@spec_root,'data','always_skip.otml')
312
311
  expected_filename = 'hash.otml'
313
312
  cache('always_skip.otml', :activity => mockup('always_skip.otml'))
314
313
  cache_size.should == 1
@@ -1,6 +1,6 @@
1
1
  module CacheHelper
2
2
  def cache(file, opts = {})
3
- options = {:url => File.join(SPEC_ROOT,'data',file), :cache_dir => @cache}.merge(opts)
3
+ options = {:url => File.join(@spec_root,'data',file), :cache_dir => @cache}.merge(opts)
4
4
  cacher = @klass.new(options)
5
5
  cacher.cache
6
6
  end
@@ -10,15 +10,13 @@ require 'fileutils'
10
10
 
11
11
  include FileUtils
12
12
 
13
- SPEC_ROOT = File.expand_path(File.dirname(__FILE__))
14
-
15
-
16
13
  describe 'Java Proxy Cacher' do
17
14
  include CacheHelper
18
15
 
19
16
  before(:each) do
20
17
  @klass = Concord::JavaProxyCacher
21
- @cache = File.join(SPEC_ROOT, "..", 'tmp','java_proxy')
18
+ @spec_root = File.expand_path(File.dirname(__FILE__))
19
+ @cache = File.join(@spec_root, "..", 'tmp','java_proxy')
22
20
  mkdir_p(@cache)
23
21
  @cache += '/'
24
22
  end
@@ -35,7 +33,7 @@ describe 'Java Proxy Cacher' do
35
33
  end
36
34
 
37
35
  it 'should create a cached file of the original url' do
38
- url = File.join(SPEC_ROOT,'data','empty.otml')
36
+ url = File.join(@spec_root,'data','empty.otml')
39
37
  expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
40
38
  cache('empty.otml')
41
39
  cache_size.should == 3
@@ -43,7 +41,7 @@ describe 'Java Proxy Cacher' do
43
41
  end
44
42
 
45
43
  it 'should create a cached header of the original url' do
46
- url = File.join(SPEC_ROOT,'data','empty.otml')
44
+ url = File.join(@spec_root,'data','empty.otml')
47
45
  expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
48
46
  cache('empty.otml')
49
47
  cache_size.should == 3
@@ -53,7 +51,7 @@ describe 'Java Proxy Cacher' do
53
51
 
54
52
  describe 'error handling' do
55
53
  it 'should handle a bad url gracefully' do
56
- url = File.join(SPEC_ROOT,'data','bad_url.otml')
54
+ url = File.join(@spec_root,'data','bad_url.otml')
57
55
  expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
58
56
 
59
57
  lambda {
@@ -67,7 +65,7 @@ describe 'Java Proxy Cacher' do
67
65
  end
68
66
 
69
67
  it 'should handle a url with trailing spaces gracefully' do
70
- url = File.join(SPEC_ROOT,'data','url_with_space.otml')
68
+ url = File.join(@spec_root,'data','url_with_space.otml')
71
69
  expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
72
70
 
73
71
  lambda {
@@ -81,7 +79,7 @@ describe 'Java Proxy Cacher' do
81
79
  end
82
80
 
83
81
  it 'should handle an empty url gracefully' do
84
- url = File.join(SPEC_ROOT,'data','empty_url.otml')
82
+ url = File.join(@spec_root,'data','empty_url.otml')
85
83
  expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
86
84
 
87
85
  lambda {
@@ -198,7 +196,7 @@ describe 'Java Proxy Cacher' do
198
196
 
199
197
  describe 'never cache' do
200
198
  it 'should always skip some references' do
201
- url = File.join(SPEC_ROOT,'data','always_skip.otml')
199
+ url = File.join(@spec_root,'data','always_skip.otml')
202
200
  expected_filename = ::Digest::SHA1.hexdigest(File.read(url))
203
201
  cache('always_skip.otml')
204
202
  cache_size.should == 3
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aaron Unger
metadata.gz.sig CHANGED
Binary file