petit 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/petit/core_ext.rb +5 -0
- data/lib/petit/router.rb +3 -3
- data/lib/petit.rb +10 -1
- data/petit.gemspec +1 -1
- data/test/links.yml +3 -3
- data/test/sample_app/links.yml +2 -2
- data/test/test_petit.rb +7 -2
- data/test/test_router.rb +1 -1
- metadata +2 -1
data/lib/petit/router.rb
CHANGED
@@ -8,9 +8,9 @@ module Petit
|
|
8
8
|
# +links+ a hash of links to redirect
|
9
9
|
def builder(links = Petit.links)
|
10
10
|
@builder ||= Rack::Builder.new do
|
11
|
-
links.each do |
|
12
|
-
map
|
13
|
-
run Proc.new {|env| RackHelper.redirect_response(
|
11
|
+
links.each do |source,dest|
|
12
|
+
map source do
|
13
|
+
run Proc.new {|env| RackHelper.redirect_response(dest)}
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/petit.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'petit/core_ext'
|
2
3
|
|
3
4
|
module Petit
|
4
5
|
|
@@ -16,7 +17,15 @@ module Petit
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def links(source = link_source)
|
19
|
-
@links
|
20
|
+
unless @links
|
21
|
+
@links = {}
|
22
|
+
links = YAML::load(File.open(source))
|
23
|
+
links.each do |key,url|
|
24
|
+
@links["/#{key}"] = url
|
25
|
+
end
|
26
|
+
@links.rename_key("/root","/")
|
27
|
+
end
|
28
|
+
@links
|
20
29
|
end
|
21
30
|
|
22
31
|
# Default way to setup petit
|
data/petit.gemspec
CHANGED
data/test/links.yml
CHANGED
data/test/sample_app/links.yml
CHANGED
data/test/test_petit.rb
CHANGED
@@ -7,7 +7,12 @@ class TestPetit < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_load_link_files
|
10
|
-
assert @links.has_key? 'foo'
|
11
|
-
assert_equal @links['foo'], 'http://bar.com'
|
10
|
+
assert @links.has_key? '/foo'
|
11
|
+
assert_equal @links['/foo'], 'http://bar.com'
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_root_link
|
15
|
+
assert_equal @links['/'], 'http://root.com'
|
12
16
|
end
|
13
17
|
end
|
18
|
+
|
data/test/test_router.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: petit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Greg Osuri
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- Rakefile
|
52
52
|
- bin/petit
|
53
53
|
- lib/petit.rb
|
54
|
+
- lib/petit/core_ext.rb
|
54
55
|
- lib/petit/rack_helper.rb
|
55
56
|
- lib/petit/router.rb
|
56
57
|
- petit.gemspec
|