p8-redirect 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +5 -4
- data/bin/redirect_app +41 -2
- data/lib/redirect.rb +1 -1
- metadata +1 -1
data/README.txt
CHANGED
@@ -4,22 +4,23 @@ http://github.com/p8/redirect/tree/master
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
Redirect is a simple Ruby redirect DSL build on Rack
|
7
|
+
Redirect is a simple Ruby redirect DSL build on Rack.
|
8
|
+
It's like a simple Ruby mod_rewrite, so you can write and test your redirects in Ruby.
|
8
9
|
|
9
|
-
== GETTING STARTED
|
10
|
+
== GETTING STARTED:
|
10
11
|
|
11
12
|
From the commandline run:
|
12
13
|
|
13
14
|
redirect_app PROJECT_NAME
|
14
15
|
|
15
|
-
This create a directory PROJECT_NAME with the required files.
|
16
|
+
This create a directory PROJECT_NAME with the required files and tests.
|
16
17
|
PROJECT_NAME.rb contains the main logic.
|
17
18
|
|
18
19
|
To locally run the app you can do:
|
19
20
|
|
20
21
|
ruby PROJECT_NAME.rb
|
21
22
|
|
22
|
-
== REDIRECTS
|
23
|
+
== REDIRECTS:
|
23
24
|
|
24
25
|
The first one is evaluated first, then the next one, etc..
|
25
26
|
|
data/bin/redirect_app
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'fileutils'
|
3
3
|
project = ARGV.first
|
4
|
-
FileUtils.mkdir_p(project
|
4
|
+
FileUtils.mkdir_p(project) unless File.directory?(project)
|
5
5
|
|
6
6
|
# create application
|
7
7
|
open("#{project}/#{project}.rb", "w") do |f|
|
@@ -18,4 +18,43 @@ open("#{project}/config.ru", "w") do |f|
|
|
18
18
|
%(Redirect.autorun = false\n\n) +
|
19
19
|
%(require '#{project}.rb'\n\n) +
|
20
20
|
%(run Redirect.app)
|
21
|
-
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# create public dir
|
24
|
+
FileUtils.mkdir_p("#{project}/public") unless File.directory?("#{project}/public")
|
25
|
+
|
26
|
+
# create tests dir
|
27
|
+
FileUtils.mkdir_p("#{project}/test") unless File.directory?("#{project}/test")
|
28
|
+
|
29
|
+
# create sample test
|
30
|
+
open("#{project}/test/#{project}_test.rb", "w") do |f|
|
31
|
+
f.puts %(require 'rubygems'
|
32
|
+
require 'test/unit'
|
33
|
+
require 'redirect'
|
34
|
+
|
35
|
+
class Test::Unit::TestCase
|
36
|
+
|
37
|
+
def assert_redirects(from, to)
|
38
|
+
res = Rack::MockRequest.new(APP[:redirect_app]).get(from)
|
39
|
+
res.headers.should == { 'Location' => to, 'Content-Type' => 'text/html' }
|
40
|
+
res.body.should == "Redirecting to: #{to}"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
APP = {}
|
46
|
+
|
47
|
+
def redirect(*redirects)
|
48
|
+
APP[:redirect_app] = Rack::Redirect.new(*redirects)
|
49
|
+
end
|
50
|
+
|
51
|
+
require File.dirname(__FILE__) + '/../#{project}.rb'
|
52
|
+
|
53
|
+
class TestClient < Test::Unit::TestCase
|
54
|
+
|
55
|
+
def test_old_url
|
56
|
+
assert_redirects('/old_url', '/new_url')
|
57
|
+
end
|
58
|
+
|
59
|
+
end)
|
60
|
+
end
|
data/lib/redirect.rb
CHANGED