royw-dvdprofiler_collection 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/dvdprofiler_collection/dvdprofiler_profile.rb +2 -0
- data/spec/cache_extensions.rb +53 -0
- data/spec/spec_helper.rb +5 -0
- metadata +4 -2
data/VERSION.yml
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
# override the classes' read_page method and replace with one
|
3
|
+
# that will cache pages in spec/samples/{url}
|
4
|
+
|
5
|
+
module CacheExtensions
|
6
|
+
# == Synopsis
|
7
|
+
# Attach the read_page and cache_file methods to the given
|
8
|
+
# class (cls) and use the given directory for the cache files
|
9
|
+
def self.attach_to(cls, directory='/tmp')
|
10
|
+
|
11
|
+
# define the read_page(page) method on the given class: cls
|
12
|
+
cls.send('define_method', "read_page") do |page|
|
13
|
+
data = nil
|
14
|
+
filespec = page.gsub(/^http:\//, directory).gsub(/\/$/, '.html')
|
15
|
+
if File.exist?(filespec)
|
16
|
+
data = open(filespec).read
|
17
|
+
else
|
18
|
+
data = open(page).read
|
19
|
+
cache_file(page, data)
|
20
|
+
end
|
21
|
+
data
|
22
|
+
end
|
23
|
+
|
24
|
+
# define the cache_file(page, data) method on the given class: cls
|
25
|
+
cls.send('define_method', "cache_file") do |page, data|
|
26
|
+
begin
|
27
|
+
filespec = page.gsub(/^http:\//, directory).gsub(/\/$/, '.html')
|
28
|
+
unless File.exist?(filespec)
|
29
|
+
puts "caching #{filespec}"
|
30
|
+
File.mkdirs(File.dirname(filespec))
|
31
|
+
File.open(filespec, 'w') { |f| f.puts data }
|
32
|
+
end
|
33
|
+
rescue Exception => eMsg
|
34
|
+
puts eMsg.to_s
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# == Synopsis
|
40
|
+
# Find all classes that have a read_page instance method and
|
41
|
+
# then overwrite that read_page method with one that handles
|
42
|
+
# the caching. Use the given directory for the cache files.
|
43
|
+
def self.attach_to_read_page_classes(directory='/tmp')
|
44
|
+
ObjectSpace.each_object(Class) do |cls|
|
45
|
+
if(cls.public_instance_methods(false).include?("read_page") ||
|
46
|
+
cls.protected_instance_methods(false).include?("read_page") ||
|
47
|
+
cls.private_instance_methods(false).include?("read_page"))
|
48
|
+
CacheExtensions.attach_to(cls, directory)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -2,9 +2,14 @@ require 'spec'
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
4
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
|
5
6
|
require 'dvdprofiler_collection'
|
6
7
|
|
7
8
|
TMPDIR = File.join(File.dirname(__FILE__), '../tmp')
|
9
|
+
SAMPLES_DIR = File.join(File.dirname(__FILE__), 'samples')
|
10
|
+
|
11
|
+
require 'cache_extensions'
|
12
|
+
CacheExtensions.attach_to_read_page_classes(SAMPLES_DIR)
|
8
13
|
|
9
14
|
Spec::Runner.configure do |config|
|
10
15
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: royw-dvdprofiler_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy Wright
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-20 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/numeric_extensions.rb
|
38
38
|
- lib/object_extensions.rb
|
39
39
|
- lib/string_extensions.rb
|
40
|
+
- spec/cache_extensions.rb
|
40
41
|
- spec/collection_spec.rb
|
41
42
|
- spec/dvdprofiler_profile_spec.rb
|
42
43
|
- spec/samples/Collection.xml
|
@@ -68,6 +69,7 @@ signing_key:
|
|
68
69
|
specification_version: 2
|
69
70
|
summary: TODO
|
70
71
|
test_files:
|
72
|
+
- spec/cache_extensions.rb
|
71
73
|
- spec/collection_spec.rb
|
72
74
|
- spec/spec_helper.rb
|
73
75
|
- spec/dvdprofiler_profile_spec.rb
|