concord_cacher 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/Rakefile CHANGED
@@ -5,19 +5,6 @@ require 'spec/rake/spectask'
5
5
 
6
6
  require './lib/concord_cacher.rb'
7
7
 
8
- require 'echoe'
9
- Echoe.new('concord_cacher', '0.1.10') do |p|
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
- p.summary = "Support for locally caching a resource and all referenced resources in multiple different ways"
12
- p.url = "http://github.com/psndcsrv/concord_cacher"
13
- p.author = "Aaron Unger"
14
- p.email = "aunger @nospam@ concord.org"
15
- p.ignore_pattern = ["tmp/*","pkg/*","hudson/*"]
16
- p.development_dependencies = []
17
- p.runtime_dependencies = []
18
- p.clean_pattern = ["hudson/*", "tmp/*"]
19
- end
20
-
21
8
  task :default => :spec
22
9
 
23
10
  Spec::Rake::SpecTask.new do |t|
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{concord_cacher}
5
- s.version = "0.1.10"
5
+ s.version = "0.1.11"
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-04-08}
10
+ s.date = %q{2010-09-07}
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/diy_local_cacher.rb", "lib/concord/filename_generators.rb", "lib/concord/filename_generators/default_generator.rb", "lib/concord/filename_generators/diy_generator.rb", "lib/concord/filename_generators/java_proxy_generator.rb", "lib/concord/helper.rb", "lib/concord/java_proxy_cacher.rb", "lib/concord/resource.rb", "lib/concord_cacher.rb"]
@@ -16,10 +16,15 @@ class ::Concord::Cacher
16
16
  ::Concord::Resource.debug = opts.delete(:debug) || false
17
17
 
18
18
  create_map = opts.delete(:create_map)
19
- ::Concord::Resource.create_map = create_map unless create_map == nil
19
+ ::Concord::Resource.create_map = create_map unless create_map.nil?
20
20
 
21
21
  cache_headers = opts.delete(:cache_headers)
22
- ::Concord::Resource.cache_headers = cache_headers unless cache_headers == nil
22
+ ::Concord::Resource.cache_headers = cache_headers unless cache_headers.nil?
23
+
24
+ relative_hosts = opts.delete(:relative)
25
+ relative_hosts = [] if relative_hosts.nil?
26
+ relative_hosts = [relative_hosts] unless relative_hosts.kind_of? Array
27
+ ::Concord::Resource.relative_hosts = relative_hosts
23
28
 
24
29
  @main_resource = Concord::Resource.new
25
30
  @main_resource.url = opts.delete(:url)
@@ -54,6 +54,7 @@ class ::Concord::Resource
54
54
  @errors = {}
55
55
  @cacher = nil
56
56
  @filename_generator = ::Concord::FilenameGenerators::DefaultGenerator
57
+ @relative_hosts = []
57
58
  class << self
58
59
  attr_accessor :debug
59
60
  attr_accessor :verbose
@@ -64,6 +65,7 @@ class ::Concord::Resource
64
65
  attr_reader :errors
65
66
  attr_accessor :cacher
66
67
  attr_accessor :filename_generator
68
+ attr_accessor :relative_hosts
67
69
  end
68
70
 
69
71
  def self.map(k,v)
@@ -160,7 +162,14 @@ class ::Concord::Resource
160
162
 
161
163
  def local_filename
162
164
  return @local_filename if @local_filename
163
- @local_filename = self.class.filename_generator.generate_filename(self)
165
+ if (self.relativize_only?)
166
+ @local_filename = self.uri.path
167
+ @local_filename << "?#{self.uri.query}" if self.uri.query
168
+ @local_filename << "##{self.uri.fragment}" if self.uri.fragment
169
+ else
170
+ @local_filename = self.class.filename_generator.generate_filename(self)
171
+ end
172
+ return @local_filename
164
173
  end
165
174
 
166
175
  def recursable?
@@ -172,6 +181,11 @@ class ::Concord::Resource
172
181
  return false
173
182
  end
174
183
 
184
+ def relativize_only?
185
+ return true if ::Concord::Resource.relative_hosts.include?(self.uri.host.to_s)
186
+ return false
187
+ end
188
+
175
189
  private
176
190
 
177
191
  def _line_matches(line)
@@ -221,6 +235,11 @@ class ::Concord::Resource
221
235
  _try(resource, lambda {
222
236
  resource.load
223
237
  })
238
+
239
+ if resource.relativize_only?
240
+ print 'r' if self.class.verbose
241
+ return
242
+ end
224
243
 
225
244
  # skip downloading already existing files.
226
245
  # because we're working with sha1 hashes we can be reasonably certain the content is a complete match
@@ -101,6 +101,16 @@ describe 'DIY Local Cacher' do
101
101
  file_content.should match(filename_for('http://portal.concord.org/images/icons/delete.png'))
102
102
  file_content.should match(filename_for('https://mail.google.com/mail/images/2/5/mountains/base/gmail_solid_white.png'))
103
103
  end
104
+
105
+ it 'should make some urls relative' do
106
+ cache('standard_uri.otml', :activity => mockup('standard_uri.otml'), :relative => ['portal.concord.org'])
107
+
108
+ file_content = File.read(File.join(@cache,'hash.otml'))
109
+
110
+ file_content.should_not match(/http:/)
111
+ file_content.should match('/images/icons/delete.png')
112
+ file_content.should match(filename_for('https://mail.google.com/mail/images/2/5/mountains/base/gmail_solid_white.png'))
113
+ end
104
114
  end
105
115
 
106
116
  describe 'element references syntax' do
@@ -239,6 +249,18 @@ describe 'DIY Local Cacher' do
239
249
  exists?(f)
240
250
  end
241
251
  end
252
+
253
+ it 'should not recurse relativized urls' do
254
+ unexpected_files = []
255
+ unexpected_files << filename_for('http://otrunk.concord.org/examples/LOOPS/models/statesofmatter/statesOfMatterPage1.cml')
256
+ unexpected_files << filename_for('http://otrunk.concord.org/examples/LOOPS/models/statesofmatter/statesOfMatterPage1$0.mml')
257
+
258
+ cache('mw_model_absolute.otml', :activity => mockup('mw_model_absolute.otml'), :relative => ['otrunk.concord.org'])
259
+
260
+ unexpected_files.each do |f|
261
+ does_not_exist?(f)
262
+ end
263
+ end
242
264
  end
243
265
 
244
266
  describe 'embedded nlogo files' do
@@ -337,5 +359,17 @@ describe 'DIY Local Cacher' do
337
359
 
338
360
  file_content.should match(Regexp.new("<OTText text=\"&lt;img src=&quot;#{filename_for("http://portal.concord.org/images/icons/chart_line.png")}&quot; /&gt;\" />"))
339
361
  end
362
+
363
+ it 'should not cause problems to specify one relative host as a string instead of an array' do
364
+ unexpected_files = []
365
+ unexpected_files << filename_for('http://otrunk.concord.org/examples/LOOPS/models/statesofmatter/statesOfMatterPage1.cml')
366
+ unexpected_files << filename_for('http://otrunk.concord.org/examples/LOOPS/models/statesofmatter/statesOfMatterPage1$0.mml')
367
+
368
+ cache('mw_model_absolute.otml', :activity => mockup('mw_model_absolute.otml'), :relative => 'otrunk.concord.org')
369
+
370
+ unexpected_files.each do |f|
371
+ does_not_exist?(f)
372
+ end
373
+ end
340
374
  end
341
375
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 10
9
- version: 0.1.10
8
+ - 11
9
+ version: 0.1.11
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-04-08 00:00:00 -04:00
38
+ date: 2010-09-07 00:00:00 -04:00
39
39
  default_executable:
40
40
  dependencies: []
41
41
 
@@ -151,6 +151,7 @@ rdoc_options:
151
151
  require_paths:
152
152
  - lib
153
153
  required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
154
155
  requirements:
155
156
  - - ">="
156
157
  - !ruby/object:Gem::Version
@@ -158,6 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
159
  - 0
159
160
  version: "0"
160
161
  required_rubygems_version: !ruby/object:Gem::Requirement
162
+ none: false
161
163
  requirements:
162
164
  - - ">="
163
165
  - !ruby/object:Gem::Version
@@ -168,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  requirements: []
169
171
 
170
172
  rubyforge_project: concord_cacher
171
- rubygems_version: 1.3.6
173
+ rubygems_version: 1.3.7
172
174
  signing_key:
173
175
  specification_version: 3
174
176
  summary: Support for locally caching a resource and all referenced resources in multiple different ways
metadata.gz.sig CHANGED
Binary file