uri_pathname 0.0.0.pre2 → 0.1.0.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/README.rdoc +58 -58
- data/examples/using_fakeweb.rb +1 -1
- data/lib/uri_pathname/version.rb +2 -2
- data/lib/uri_pathname.rb +1 -1
- data/uri_pathname.gemspec +3 -3
- metadata +9 -12
data/README.rdoc
CHANGED
@@ -69,65 +69,65 @@ register fake accesses to real URIs.
|
|
69
69
|
This example shows how tu use UriPathname to assign names to files and also
|
70
70
|
registering those files to stubb real accesses later.
|
71
71
|
|
72
|
-
require 'rubygems'
|
73
|
-
require 'fileutils'
|
74
|
-
require 'open-uri'
|
75
|
-
require 'uri_pathname'
|
76
|
-
require 'fakeweb' # gem install fakeweb
|
77
|
-
|
78
|
-
# put here whatever temporary directory name to use
|
79
|
-
MY_DIR=File.expand_path '~/my_dumps'
|
80
|
-
# put here whatever URIs u want to access
|
81
|
-
MY_URIS = [
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
]
|
87
|
-
|
88
|
-
# some convenient defs
|
89
|
-
def prepare_example
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
# preparation (comment this if you've already got your test dir)
|
94
|
-
prepare_example
|
95
|
-
|
96
|
-
up = UriPathname.new
|
97
|
-
|
98
|
-
# 1st round: Capture MY_URIS, and save them with appropiate UriPathname
|
99
|
-
puts "1- Capturing URIs"
|
100
|
-
data = nil
|
101
|
-
sizes = []
|
102
|
-
MY_URIS.each do |uri|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
72
|
+
require 'rubygems'
|
73
|
+
require 'fileutils'
|
74
|
+
require 'open-uri'
|
75
|
+
require 'uri_pathname'
|
76
|
+
require 'fakeweb' # gem install fakeweb
|
77
|
+
|
78
|
+
# put here whatever temporary directory name to use
|
79
|
+
MY_DIR=File.expand_path '~/my_dumps'
|
80
|
+
# put here whatever URIs u want to access
|
81
|
+
MY_URIS = [
|
82
|
+
'http://en.wikipedia.org/wiki/Ruby_Bridges',
|
83
|
+
'http://donaldfagen.com/disc_nightfly.php',
|
84
|
+
'http://www.rubi.cat/ajrubi/portada/index.php',
|
85
|
+
'http://www.google.com/cse?q=array&cx=013598269713424429640%3Ag5orptiw95w&ie=UTF-8&sa=Search'
|
86
|
+
]
|
87
|
+
|
88
|
+
# some convenient defs
|
89
|
+
def prepare_example
|
90
|
+
File.makedirs(MY_DIR) unless (File.exist?(MY_DIR) and File.directory?(MY_DIR))
|
91
|
+
end
|
92
|
+
|
93
|
+
# preparation (comment this if you've already got your test dir)
|
94
|
+
prepare_example
|
95
|
+
|
96
|
+
up = UriPathname.new
|
97
|
+
|
98
|
+
# 1st round: Capture MY_URIS, and save them with appropiate UriPathname
|
99
|
+
puts "1- Capturing URIs"
|
100
|
+
data = nil
|
101
|
+
sizes = []
|
102
|
+
MY_URIS.each do |uri|
|
103
|
+
open uri do |u|
|
104
|
+
data=u.read
|
105
|
+
pathname = up.uri_to_pathname(uri,MY_DIR,".html")
|
106
|
+
File.open(pathname,'w') do |f|
|
107
|
+
f.write data
|
108
|
+
sizes << data.size
|
109
|
+
puts "SAVED #{uri} : #{data.size} bytes"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# 2nd round: checking saved files and preparing fake web accesses
|
115
|
+
puts "\n2- CHECKING CAPTURED FILES AND PREPARING FAKE WEB ACCESSES"
|
116
|
+
FakeWeb.allow_net_connect=false
|
117
|
+
Dir[File.join(MY_DIR,"*")].each do |name|
|
118
|
+
uri = up.pathname_to_uri name
|
119
|
+
FakeWeb.register_uri :any, uri, :body=>name, :content_type=>"text/html"
|
120
|
+
puts "#{name}\n\tcorresponds to #{uri}"
|
121
|
+
end
|
122
|
+
|
123
|
+
# 3nd round: Access Web without actually accessing web
|
124
|
+
puts "\n3- FAKE WEB ACCESSES"
|
125
|
+
MY_URIS.each_with_index do |uri,i|
|
126
|
+
open uri do |u|
|
127
|
+
data=u.read
|
128
|
+
puts "FAKE #{uri} ACCESS #{(data.size == sizes[i]) ? 'OK' : 'KO'}: #{data.size} bytes"
|
129
|
+
end
|
110
130
|
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# 2nd round: checking saved files and preparing
|
115
|
-
puts "\n2- CHECKING CAPTURED FILES AND PREPARING FAKE WEB ACCESSES"
|
116
|
-
FakeWeb.allow_net_connect=false
|
117
|
-
Dir[File.join(MY_DIR,"*")].each do |name|
|
118
|
-
uri = up.pathname_to_uri name
|
119
|
-
FakeWeb.register_uri :any, uri, :body=>name, :content_type=>"text/html"
|
120
|
-
puts "#{name}\n\tcorresponds to #{uri}"
|
121
|
-
end
|
122
|
-
|
123
|
-
# 3nd round: Access Web without actually accessing web
|
124
|
-
puts "\n3- FAKE WEB ACCESSES"
|
125
|
-
MY_URIS.each_with_index do |uri,i|
|
126
|
-
open uri do |u|
|
127
|
-
data=u.read
|
128
|
-
puts "FAKE #{uri} ACCESS #{(data.size == sizes[i]) ? 'OK' : 'KO'}: #{data.size} bytes"
|
129
|
-
end
|
130
|
-
end
|
131
131
|
|
132
132
|
== Release Notes
|
133
133
|
|
data/examples/using_fakeweb.rb
CHANGED
@@ -47,7 +47,7 @@ MY_URIS.each do |uri|
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
# 2nd round: checking saved files and preparing
|
50
|
+
# 2nd round: checking saved files and preparing fake web accesses
|
51
51
|
puts "\n2- CHECKING CAPTURED FILES AND PREPARING FAKE WEB ACCESSES"
|
52
52
|
FakeWeb.allow_net_connect=false
|
53
53
|
Dir[File.join(MY_DIR,"*")].each do |name|
|
data/lib/uri_pathname/version.rb
CHANGED
data/lib/uri_pathname.rb
CHANGED
@@ -14,7 +14,7 @@ class UriPathname
|
|
14
14
|
# pathname and viceversa. To work it should be a String that
|
15
15
|
# doesn't exist in URIs and that can be used in pathnames.
|
16
16
|
|
17
|
-
HOST_SEP = '__|' # used to separate hostname from the
|
17
|
+
HOST_SEP = '__|' # used to separate hostname from the path
|
18
18
|
|
19
19
|
NO_PTH = '_NOPATH_' # used to make a filename for root uris (empty path).
|
20
20
|
# To work it should be a String that doesn't exist in uris
|
data/uri_pathname.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "uri_pathname"
|
8
|
-
s.version = "0.0.0
|
8
|
+
s.version = "0.1.0.0"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marcel Massana"]
|
12
|
-
s.date = "2011-08-
|
12
|
+
s.date = "2011-08-31"
|
13
13
|
s.description = "Simple converter between URIs and Pathnames. It creates valid, unique and readable filenames from URIs and viceversa. It can be used to name files while saving data from websites and conversely, read files assigned to URIs while, for instance, simulating or stubbing web accesses by means of reading files"
|
14
14
|
s.email = "xaxaupua@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uri_pathname
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 71
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
10
|
- 0
|
10
|
-
|
11
|
-
- 2
|
12
|
-
version: 0.0.0.pre2
|
11
|
+
version: 0.1.0.0
|
13
12
|
platform: ruby
|
14
13
|
authors:
|
15
14
|
- Marcel Massana
|
@@ -17,7 +16,7 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date: 2011-08-
|
19
|
+
date: 2011-08-31 00:00:00 Z
|
21
20
|
dependencies: []
|
22
21
|
|
23
22
|
description: Simple converter between URIs and Pathnames. It creates valid, unique and readable filenames from URIs and viceversa. It can be used to name files while saving data from websites and conversely, read files assigned to URIs while, for instance, simulating or stubbing web accesses by means of reading files
|
@@ -61,14 +60,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
|
-
- - "
|
63
|
+
- - ">="
|
65
64
|
- !ruby/object:Gem::Version
|
66
|
-
hash:
|
65
|
+
hash: 3
|
67
66
|
segments:
|
68
|
-
-
|
69
|
-
|
70
|
-
- 1
|
71
|
-
version: 1.3.1
|
67
|
+
- 0
|
68
|
+
version: "0"
|
72
69
|
requirements: []
|
73
70
|
|
74
71
|
rubyforge_project:
|