sinatra-advanced-routes 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.md +6 -0
- data/README.md +61 -57
- data/lib/sinatra/advanced/routes.rb +1 -0
- data/spec/sinatra/advanced_routes_spec.rb +19 -4
- data/spec/spec_helper.rb +10 -2
- metadata +114 -99
data/NEWS.md
ADDED
data/README.md
CHANGED
@@ -1,75 +1,79 @@
|
|
1
|
-
Sinatra::AdvancedRoutes
|
2
|
-
=======================
|
1
|
+
# Sinatra::AdvancedRoutes
|
3
2
|
|
4
|
-
Makes routes first class objects in [Sinatra](http://sinatrarb.com).
|
3
|
+
> Makes routes first class objects in [Sinatra](http://sinatrarb.com).
|
5
4
|
|
6
|
-
|
7
|
-
-------
|
5
|
+
[![Build Status](https://travis-ci.org/rkh/sinatra-advanced-routes.png)](https://travis-ci.org/rkh/sinatra-advanced-routes)
|
8
6
|
|
9
|
-
|
10
|
-
Check it out if you are looking for other fancy Sinatra extensions.
|
7
|
+
Check out [sinatra-contrib](https://github.com/sinatra/sinatra-contrib) you are looking for other fancy Sinatra extensions.
|
11
8
|
|
12
|
-
Installation
|
13
|
-
------------
|
9
|
+
## Installation
|
14
10
|
|
15
|
-
|
11
|
+
Add to your `Gemfile` :
|
16
12
|
|
17
|
-
|
18
|
-
|
13
|
+
```ruby
|
14
|
+
gem 'sinatra-advanced-routes'
|
15
|
+
```
|
19
16
|
|
20
|
-
|
17
|
+
If you are extending Sinatra::Base, register the extension manually :
|
21
18
|
|
22
|
-
|
23
|
-
|
19
|
+
```ruby
|
20
|
+
require "sinatra/base"
|
21
|
+
require "sinatra/advanced_routes"
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
class Foo < Sinatra::Base
|
24
|
+
register Sinatra::AdvancedRoutes
|
25
|
+
end
|
26
|
+
```
|
28
27
|
|
29
|
-
|
30
|
-
# Let's deactivate the route if we have no password file.
|
31
|
-
if File.exists? "admin_password" then admin_route.activate
|
32
|
-
else admin_route.deactivate
|
33
|
-
end
|
34
|
-
end
|
28
|
+
## Examples
|
35
29
|
|
36
|
-
|
37
|
-
# stuff
|
38
|
-
end
|
30
|
+
### Route manipulation
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
```ruby
|
33
|
+
require "sinatra"
|
34
|
+
require "sinatra/advanced_routes"
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
admin_route = get "/admin" do
|
37
|
+
administrate_stuff
|
38
|
+
end
|
47
39
|
|
48
|
-
|
40
|
+
before do
|
41
|
+
# Let's deactivate the route if we have no password file.
|
42
|
+
if File.exists? "admin_password" then admin_route.activate
|
43
|
+
else admin_route.deactivate
|
44
|
+
end
|
45
|
+
end
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
puts "-"*20
|
54
|
-
puts route.app.name # "SomeSinatraApp"
|
55
|
-
puts route.path # that's the path given as argument to get and akin
|
56
|
-
puts route.verb # get / head / post / put / delete
|
57
|
-
puts route.file # "some_sinatra_app.rb" or something
|
58
|
-
puts route.line # the line number of the get/post/... statement
|
59
|
-
puts route.pattern # that's the pattern internally used by sinatra
|
60
|
-
puts route.keys # keys given when route was defined
|
61
|
-
puts route.conditions # conditions given when route was defined
|
62
|
-
puts route.block # the route's closure
|
63
|
-
end
|
47
|
+
first_route = get "/:name" do
|
48
|
+
# stuff
|
49
|
+
end
|
64
50
|
|
65
|
-
|
51
|
+
other_route = get "/foo_:name" do
|
52
|
+
# other stuff
|
53
|
+
end
|
54
|
+
|
55
|
+
# Unfortunatly first_route will catch all the requests other_route would
|
56
|
+
# have gotten, since it has been defined first. But wait, we can fix this!
|
57
|
+
other_route.promote
|
58
|
+
```
|
59
|
+
|
60
|
+
### Route inspection
|
66
61
|
|
67
|
-
|
68
|
-
|
62
|
+
```ruby
|
63
|
+
require "some_sinatra_app"
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
65
|
+
SomeSinatraApp.each_route do |route|
|
66
|
+
puts "-" * 20
|
67
|
+
puts route.app.name # "SomeSinatraApp"
|
68
|
+
puts route.path # that's the path given as argument to get and akin
|
69
|
+
puts route.verb # get / head / post / put / delete
|
70
|
+
puts route.file # "some_sinatra_app.rb" or something
|
71
|
+
puts route.line # the line number of the get/post/... statement
|
72
|
+
puts route.pattern # that's the pattern internally used by sinatra
|
73
|
+
puts route.keys # keys given when route was defined
|
74
|
+
puts route.conditions # conditions given when route was defined
|
75
|
+
puts route.block # the route's closure
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
Some of that fields (like conditions or pattern) can be changed, which will take immediate effect on the routing.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sinatra/advanced_routes'
|
@@ -1,10 +1,16 @@
|
|
1
1
|
require File.expand_path("../../spec_helper", __FILE__)
|
2
2
|
|
3
|
+
set :environment, :test
|
4
|
+
|
3
5
|
describe Sinatra::AdvancedRoutes do
|
4
|
-
before { app :AdvancedRoutes }
|
5
|
-
it_should_behave_like 'sinatra'
|
6
6
|
|
7
|
-
|
7
|
+
def app
|
8
|
+
Sinatra::Application
|
9
|
+
end
|
10
|
+
|
11
|
+
before { mock_app { register Sinatra::AdvancedRoutes }}
|
12
|
+
|
13
|
+
[:head, :get, :post, :put, :delete].each do |verb|
|
8
14
|
describe "HTTP #{verb.to_s.upcase}" do
|
9
15
|
|
10
16
|
describe "activation" do
|
@@ -18,7 +24,7 @@ describe Sinatra::AdvancedRoutes do
|
|
18
24
|
browse_route(verb, "/foo").should_not be_ok
|
19
25
|
end
|
20
26
|
|
21
|
-
it "is able to
|
27
|
+
it "is able to deactivate routes from a before filter" do
|
22
28
|
route = define_route(verb, "/foo") { "bar" }
|
23
29
|
app.before { route.deactivate }
|
24
30
|
route.should be_active
|
@@ -91,4 +97,13 @@ describe Sinatra::AdvancedRoutes do
|
|
91
97
|
|
92
98
|
end
|
93
99
|
end
|
100
|
+
|
101
|
+
def define_route(verb, *args, &block)
|
102
|
+
app.send(verb, *args, &block)
|
103
|
+
end
|
104
|
+
|
105
|
+
def browse_route(verb, *args, &block)
|
106
|
+
send(verb, *args, &block)
|
107
|
+
last_response
|
108
|
+
end
|
94
109
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra/test_helpers'
|
3
|
+
require 'sinatra/advanced_routes'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.include Rack::Test::Methods
|
9
|
+
config.include Sinatra::TestHelpers
|
10
|
+
end
|
metadata
CHANGED
@@ -1,149 +1,164 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-advanced-routes
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 1
|
10
|
-
version: 0.5.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.2
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Konstantin Haase
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-01-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: monkey-lib
|
23
16
|
prerelease: false
|
24
|
-
requirement:
|
25
|
-
|
26
|
-
requirements:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
27
19
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 11
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 5
|
33
|
-
- 0
|
20
|
+
- !ruby/object:Gem::Version
|
34
21
|
version: 0.5.0
|
22
|
+
none: false
|
35
23
|
type: :runtime
|
36
|
-
version_requirements:
|
37
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.5.0
|
29
|
+
none: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
38
31
|
name: sinatra-sugar
|
39
32
|
prerelease: false
|
40
|
-
requirement:
|
41
|
-
|
42
|
-
requirements:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
43
35
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
hash: 11
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 5
|
49
|
-
- 0
|
36
|
+
- !ruby/object:Gem::Version
|
50
37
|
version: 0.5.0
|
51
|
-
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: sinatra-test-helper
|
55
|
-
prerelease: false
|
56
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
57
38
|
none: false
|
58
|
-
|
39
|
+
type: :runtime
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
59
42
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
hash: 11
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
- 5
|
65
|
-
- 0
|
43
|
+
- !ruby/object:Gem::Version
|
66
44
|
version: 0.5.0
|
45
|
+
none: false
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rack-test
|
48
|
+
prerelease: false
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
none: false
|
67
55
|
type: :development
|
68
|
-
version_requirements:
|
69
|
-
|
70
|
-
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
none: false
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
prerelease: false
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
none: false
|
71
|
+
type: :development
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
none: false
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: sinatra-contrib
|
71
80
|
prerelease: false
|
72
|
-
requirement:
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
none: false
|
87
|
+
type: :development
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
73
93
|
none: false
|
74
|
-
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: sinatra
|
96
|
+
prerelease: false
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
75
99
|
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
79
|
-
- 1
|
80
|
-
- 0
|
81
|
-
version: "1.0"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.0'
|
102
|
+
none: false
|
82
103
|
type: :runtime
|
83
|
-
version_requirements:
|
84
|
-
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '1.0'
|
109
|
+
none: false
|
110
|
+
- !ruby/object:Gem::Dependency
|
85
111
|
name: rspec
|
86
112
|
prerelease: false
|
87
|
-
requirement:
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
hash: 27
|
93
|
-
segments:
|
94
|
-
- 1
|
95
|
-
- 3
|
96
|
-
- 0
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
97
117
|
version: 1.3.0
|
118
|
+
none: false
|
98
119
|
type: :development
|
99
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.0
|
125
|
+
none: false
|
100
126
|
description: Make Sinatra routes first class objects (part of BigBand).
|
101
127
|
email: konstantin.mailinglists@googlemail.com
|
102
128
|
executables: []
|
103
|
-
|
104
129
|
extensions: []
|
105
|
-
|
106
130
|
extra_rdoc_files: []
|
107
|
-
|
108
|
-
|
131
|
+
files:
|
132
|
+
- lib/sinatra/advanced/routes.rb
|
109
133
|
- lib/sinatra/advanced_routes.rb
|
110
134
|
- spec/sinatra/advanced_routes_spec.rb
|
111
135
|
- spec/spec_helper.rb
|
136
|
+
- NEWS.md
|
112
137
|
- README.md
|
113
138
|
- LICENSE
|
114
|
-
has_rdoc: yard
|
115
139
|
homepage: http://github.com/rkh/sinatra-advanced-routes
|
116
140
|
licenses: []
|
117
|
-
|
118
141
|
post_install_message:
|
119
142
|
rdoc_options: []
|
120
|
-
|
121
|
-
require_paths:
|
143
|
+
require_paths:
|
122
144
|
- lib
|
123
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
124
150
|
none: false
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
- 0
|
131
|
-
version: "0"
|
132
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ! '>='
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
133
156
|
none: false
|
134
|
-
requirements:
|
135
|
-
- - ">="
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
hash: 3
|
138
|
-
segments:
|
139
|
-
- 0
|
140
|
-
version: "0"
|
141
157
|
requirements: []
|
142
|
-
|
143
158
|
rubyforge_project:
|
144
|
-
rubygems_version: 1.
|
159
|
+
rubygems_version: 1.8.24
|
145
160
|
signing_key:
|
146
161
|
specification_version: 3
|
147
162
|
summary: Make Sinatra routes first class objects (part of BigBand).
|
148
163
|
test_files: []
|
149
|
-
|
164
|
+
has_rdoc: yard
|