petit 0.0.1 → 0.0.2

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.
@@ -0,0 +1,5 @@
1
+ class Hash
2
+ def rename_key(old,new)
3
+ self[new] = self.delete(old)
4
+ end
5
+ end
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 |key,url|
12
- map "/#{key}" do
13
- run Proc.new {|env| RackHelper.redirect_response(url)}
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 ||= YAML::load(File.open(source))
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
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "petit"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.2"
7
7
  s.authors = ["Greg Osuri"]
8
8
  s.email = ["gosuri@gmail.com"]
9
9
  s.homepage = "http://gosuri.github.com/petit"
data/test/links.yml CHANGED
@@ -1,4 +1,4 @@
1
+ root: http://root.com
1
2
  foo: http://bar.com
2
- beth: http://beatty.net
3
- m: http://morissettedibbert.name
4
- h: http://hamill.name
3
+ a: http://apple.com
4
+ g: http://google.com
@@ -1,4 +1,4 @@
1
- g: http://gregosuri.com
2
- gb: http://gridbag.com
1
+ root: http://gregosuri.com
2
+ gb: http://gridbag.com
3
3
  # Links go here
4
4
  # foo: http://bar.com # => will redirect yourdomain/foo to http://bar.com
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
@@ -4,7 +4,7 @@ require 'rack/mock'
4
4
  class TestRouter < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
- @links = {"foo" => "http://bar.com"}
7
+ @links = {"/foo" => "http://bar.com"}
8
8
  end
9
9
 
10
10
  def test_builder
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: petit
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
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