named-routes 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,6 +6,8 @@ A simple and generic named routes api. It works really well with Sinatra.
6
6
 
7
7
  gem install named-routes
8
8
 
9
+ require "named-routes"
10
+
9
11
  ## Route Definitions
10
12
 
11
13
  You can define a named route by providing the name of the method and the definition.
@@ -35,7 +37,7 @@ If you have multiple handlers for the same route, you can use the block syntax:
35
37
  You can also define prefixes on the route definitions:
36
38
 
37
39
  include NamedRoutes
38
- routes.prefix = "admin"
40
+ paths.prefix = "admin"
39
41
 
40
42
  path(:user, "/users/:user_id") do |_| # => /admin/users/:user_id
41
43
  get _ do
@@ -52,29 +54,29 @@ You can also define prefixes on the route definitions:
52
54
  You can access the routes by doing the following.
53
55
 
54
56
  include NamedRoutes
55
- routes.host = "example.com"
57
+ paths.host = "example.com"
56
58
  path(:user, "/users/:user_id")
57
- routes.user(:user_id => 42) # => "/users/42"
58
- routes.http.user(:user_id => 42) # => "http://example.com/users/42"
59
- routes.https.user(:user_id => 42) # => "http://example.com/users/42"
59
+ paths.user(:user_id => 42) # => "/users/42"
60
+ paths.http.user(:user_id => 42) # => "http://example.com/users/42"
61
+ paths.https.user(:user_id => 42) # => "http://example.com/users/42"
60
62
 
61
63
  It also works with prefixes:
62
64
 
63
65
  include NamedRoutes
64
- routes.host = "example.com"
65
- routes.prefix = "admin"
66
+ paths.host = "example.com"
67
+ paths.prefix = "admin"
66
68
  path(:user, "/users/:user_id")
67
- routes.user(:user_id => 42) # => "/users/42"
68
- routes.http.user(:user_id => 42) # => "http://example.com/admin/users/42"
69
- routes.https.user(:user_id => 42) # => "http://example.com/admin/users/42"
69
+ paths.user(:user_id => 42) # => "/users/42"
70
+ paths.http.user(:user_id => 42) # => "http://example.com/admin/users/42"
71
+ paths.https.user(:user_id => 42) # => "http://example.com/admin/users/42"
70
72
 
71
73
  And with query params:
72
74
 
73
75
  include NamedRoutes
74
- routes.host = "example.com"
75
- routes.prefix = "admin"
76
+ paths.host = "example.com"
77
+ paths.prefix = "admin"
76
78
  path(:user, "/users/:user_id")
77
- routes.user(:user_id => 42, :foo => "bar of soap") # => "/users/42&foo=bar+of+soap"
79
+ paths.user(:user_id => 42, :foo => "bar of soap") # => "/users/42&foo=bar+of+soap"
78
80
 
79
81
  ## Advanced Usages
80
82
 
@@ -88,24 +90,24 @@ You can also inherit Routes to have different sets of Routes. This is useful if
88
90
  self.prefix = "partay"
89
91
  end
90
92
 
91
- def admin_routes
93
+ def admin_paths
92
94
  AdminRoutes
93
95
  end
94
96
 
95
- def partay_routes
97
+ def partay_paths
96
98
  PartayRoutes
97
99
  end
98
100
 
99
- get admin_routes.path(:user, "/users/:user_id") do # => /admin/users/:user_id
101
+ get admin_paths.path(:user, "/users/:user_id") do # => /admin/users/:user_id
100
102
  # ...
101
103
  end
102
104
 
103
- admin_routes.user(:user_id => 42) # => "/admin/users/42"
105
+ admin_paths.user(:user_id => 42) # => "/admin/users/42"
104
106
 
105
- get partay_routes.path(:user, "/users/:user_id") do # => /partay/users/:user_id
107
+ get partay_paths.path(:user, "/users/:user_id") do # => /partay/users/:user_id
106
108
  # ...
107
109
  end
108
110
 
109
- partay_routes.user(:user_id => 42, :beer => "pabst") # => "/partay/users/42&beer=pabst"
111
+ partay_paths.user(:user_id => 42, :beer => "pabst") # => "/partay/users/42&beer=pabst"
110
112
 
111
113
  Copyright (c) 2010 Brian Takita. This software is licensed under the MIT License.
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ begin
22
22
  s.has_rdoc = true
23
23
  s.extra_rdoc_files = [ "README.md", "CHANGES" ]
24
24
  s.rdoc_options = ["--main", "README.md", "--inline-source", "--line-numbers"]
25
+ s.add_dependency "activesupport", ">= 2.3"
25
26
  end
26
27
  rescue LoadError
27
28
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
data/lib/named-routes.rb CHANGED
@@ -1,7 +1,4 @@
1
- require "active_support"
2
- require "active_support/hash_with_indifferent_access"
3
- require "active_support/core_ext"
4
- require "active_support/core_ext"
1
+ require "extlib"
5
2
  require "uri"
6
3
 
7
4
  module NamedRoutes
@@ -9,9 +6,11 @@ module NamedRoutes
9
6
  routes.path(*args, &block)
10
7
  end
11
8
 
12
- def routes
9
+ def paths
13
10
  ::NamedRoutes::Routes
14
11
  end
12
+ alias_method :routes, :paths
13
+
15
14
  extend self
16
15
  end
17
16
 
@@ -25,7 +25,7 @@ module NamedRoutes
25
25
  end
26
26
 
27
27
  def eval(definition, params_arg={})
28
- params = ActiveSupport::HashWithIndifferentAccess.new(params_arg)
28
+ params = Mash.new(params_arg)
29
29
  path_string = if params.empty?
30
30
  definition
31
31
  else
@@ -42,7 +42,7 @@ module NamedRoutes
42
42
  end.join("/")
43
43
  end
44
44
  unless params.empty?
45
- path_string << "?#{params.to_param}"
45
+ path_string << "?#{escape_params(params).to_params.gsub("%20", "+")}"
46
46
  end
47
47
  path_string
48
48
  end
@@ -98,7 +98,7 @@ module NamedRoutes
98
98
 
99
99
  context "when there is no prefix" do
100
100
  before do
101
- routes.prefix.should_not be_present
101
+ routes.prefix.should == nil
102
102
  end
103
103
 
104
104
  it "returns the given path" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: named-routes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Takita
@@ -17,8 +17,22 @@ cert_chain: []
17
17
 
18
18
  date: 2010-10-20 00:00:00 -07:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 2
32
+ - 3
33
+ version: "2.3"
34
+ type: :runtime
35
+ version_requirements: *id001
22
36
  description:
23
37
  email: brian.takita@gmail.com
24
38
  executables: []