redirect 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +1 -0
- data/README.txt +1 -1
- data/Rakefile +2 -2
- data/example.ru +7 -0
- data/lib/redirect.rb +33 -14
- data/spec/rack_spec.rb +14 -0
- metadata +3 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/README.txt
CHANGED
@@ -16,7 +16,7 @@ Create a file and pass an array to the redirect method:
|
|
16
16
|
['^/some_regexp', '/all']
|
17
17
|
|
18
18
|
The catch_url can be a regular expression.
|
19
|
-
You can overwrite the
|
19
|
+
You can overwrite the http code (defaults is 301) in the options and pass a name for the sitemap.
|
20
20
|
|
21
21
|
The default redirect code can be changed:
|
22
22
|
|
data/Rakefile
CHANGED
@@ -10,9 +10,9 @@ if defined? Hoe
|
|
10
10
|
p.remote_rdoc_dir = '' # Release to root
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# require 'metric_fu'
|
15
15
|
#
|
16
16
|
# MetricFu::Configuration.run do |config|
|
17
|
-
# config.coverage = { :test_files => ['
|
17
|
+
# config.coverage = { :test_files => ['spec/**/*_spec.rb'] }
|
18
18
|
# end
|
data/example.ru
ADDED
data/lib/redirect.rb
CHANGED
@@ -5,7 +5,32 @@ require 'rack/request'
|
|
5
5
|
require 'rack/response'
|
6
6
|
|
7
7
|
module Redirect
|
8
|
-
VERSION = '0.0
|
8
|
+
VERSION = '0.1.0'
|
9
|
+
|
10
|
+
def self.default_code= default_code
|
11
|
+
@default_code = default_code
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.default_code
|
15
|
+
@default_code ||= 301
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.autorun= autorun
|
19
|
+
@autorun = autorun
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.autorun
|
23
|
+
@autorun = true unless @autorun == false
|
24
|
+
@autorun
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.app= app
|
28
|
+
@app = app
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.app
|
32
|
+
@app
|
33
|
+
end
|
9
34
|
|
10
35
|
class Data
|
11
36
|
attr_reader :catch_url, :redirect_url, :code, :name
|
@@ -16,24 +41,18 @@ module Redirect
|
|
16
41
|
@name = options[:name]
|
17
42
|
end
|
18
43
|
end
|
19
|
-
|
20
|
-
def self.default_code= default_code
|
21
|
-
@default_code = default_code
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.default_code
|
25
|
-
@default_code ||= 301
|
26
|
-
end
|
27
44
|
|
28
45
|
end
|
29
46
|
|
30
47
|
def redirect(*redirects)
|
31
48
|
|
32
|
-
app = Rack::Redirect.new(*redirects)
|
33
|
-
|
34
|
-
Rack::
|
35
|
-
|
36
|
-
|
49
|
+
Redirect.app = Rack::Redirect.new(*redirects)
|
50
|
+
if Redirect.autorun
|
51
|
+
Rack::Handler::WEBrick.run \
|
52
|
+
Rack::ShowExceptions.new(Rack::Lint.new(Redirect.app)),
|
53
|
+
:Port => 3000
|
54
|
+
run Redirect.app
|
55
|
+
end
|
37
56
|
end
|
38
57
|
|
39
58
|
module Rack
|
data/spec/rack_spec.rb
CHANGED
@@ -103,6 +103,8 @@ end
|
|
103
103
|
describe "Redirect" do
|
104
104
|
after do
|
105
105
|
Redirect.default_code = 301
|
106
|
+
Redirect.app = nil
|
107
|
+
Redirect.autorun = true
|
106
108
|
end
|
107
109
|
|
108
110
|
it "Should be able to configure the default http code" do
|
@@ -113,4 +115,16 @@ describe "Redirect" do
|
|
113
115
|
data.code.should == 307
|
114
116
|
end
|
115
117
|
|
118
|
+
it "Should be able to set app" do
|
119
|
+
Redirect.app.should == nil
|
120
|
+
Redirect.app = 'a'
|
121
|
+
Redirect.app.should == 'a'
|
122
|
+
end
|
123
|
+
|
124
|
+
it "Should be able to set autorun" do
|
125
|
+
Redirect.autorun.should == true
|
126
|
+
Redirect.autorun = false
|
127
|
+
Redirect.autorun.should == false
|
128
|
+
end
|
129
|
+
|
116
130
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petrik de Heus
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-22 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- README.txt
|
40
40
|
- Rakefile
|
41
41
|
- example.rb
|
42
|
+
- example.ru
|
42
43
|
- lib/redirect.rb
|
43
44
|
- spec/helper.rb
|
44
45
|
- spec/rack_spec.rb
|