lotus-router 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +45 -0
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +33 -9
- data/lib/lotus/router.rb +98 -0
- data/lib/lotus/router/version.rb +1 -1
- data/lib/lotus/routing/endpoint.rb +1 -1
- data/lib/lotus/routing/endpoint_resolver.rb +23 -3
- data/lib/lotus/routing/http_router.rb +12 -0
- data/lib/lotus/routing/resource/options.rb +27 -2
- data/lotus-router.gemspec +1 -1
- metadata +6 -46
- data/.coveralls.yml +0 -2
- data/.gitignore +0 -9
- data/.travis.yml +0 -5
- data/.yardopts +0 -3
- data/Gemfile +0 -11
- data/Rakefile +0 -10
- data/benchmarks/callable +0 -23
- data/benchmarks/named_routes +0 -72
- data/benchmarks/resource +0 -44
- data/benchmarks/resources +0 -58
- data/benchmarks/routes +0 -67
- data/benchmarks/run.sh +0 -11
- data/benchmarks/utils.rb +0 -56
- data/test/fixtures.rb +0 -193
- data/test/integration/client_error_test.rb +0 -16
- data/test/integration/pass_on_response_test.rb +0 -13
- data/test/named_routes_test.rb +0 -123
- data/test/namespace_test.rb +0 -289
- data/test/new_test.rb +0 -67
- data/test/redirect_test.rb +0 -33
- data/test/resource_test.rb +0 -128
- data/test/resources_test.rb +0 -136
- data/test/routing/endpoint_resolver_test.rb +0 -110
- data/test/routing/resource/options_test.rb +0 -36
- data/test/routing_test.rb +0 -99
- data/test/test_helper.rb +0 -32
- data/test/version_test.rb +0 -7
data/.coveralls.yml
DELETED
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/.yardopts
DELETED
data/Gemfile
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
source 'http://rubygems.org'
|
2
|
-
gemspec
|
3
|
-
|
4
|
-
unless ENV['TRAVIS']
|
5
|
-
gem 'debugger', require: false, platforms: :ruby
|
6
|
-
gem 'yard', require: false
|
7
|
-
gem 'simplecov', require: false
|
8
|
-
gem 'lotus-utils', require: false, path: '../lotus-utils'
|
9
|
-
end
|
10
|
-
|
11
|
-
gem 'coveralls', require: false
|
data/Rakefile
DELETED
data/benchmarks/callable
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -W0
|
2
|
-
load File.dirname(__FILE__) + '/utils.rb'
|
3
|
-
|
4
|
-
Benchmark.bm(50) do |b|
|
5
|
-
##
|
6
|
-
# Callable
|
7
|
-
#
|
8
|
-
router = Lotus::Router.new
|
9
|
-
app = Rack::MockRequest.new(router)
|
10
|
-
|
11
|
-
b.report 'generating from callable endpoints' do
|
12
|
-
$callable.each do |route|
|
13
|
-
router.get route, &$endpoint
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
b.report 'recognizing from callable endpoints' do
|
18
|
-
TIMES.times do
|
19
|
-
app.get($callable.sample)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
data/benchmarks/named_routes
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -W0
|
2
|
-
load File.dirname(__FILE__) + '/utils.rb'
|
3
|
-
|
4
|
-
Benchmark.bm(50) do |b|
|
5
|
-
|
6
|
-
##
|
7
|
-
# Callable
|
8
|
-
#
|
9
|
-
router = Lotus::Router.new
|
10
|
-
app = Rack::MockRequest.new(router)
|
11
|
-
|
12
|
-
b.report 'generating named routes' do
|
13
|
-
$named_routes.each do |(name, as)|
|
14
|
-
router.get name, to: $endpoint, as: as
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
b.report 'recognizing named routes' do
|
19
|
-
TIMES.times do
|
20
|
-
app.get($named_routes.sample.first)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Class
|
26
|
-
#
|
27
|
-
router = Lotus::Router.new
|
28
|
-
app = Rack::MockRequest.new(router)
|
29
|
-
|
30
|
-
$named_routes.each do |(name, _)|
|
31
|
-
eval "#{ Lotus::Utils::String.new(name).classify } = Class.new($controller)"
|
32
|
-
end
|
33
|
-
|
34
|
-
b.report 'generating named routes (class endpoints)' do
|
35
|
-
$named_routes.each do |(name, as)|
|
36
|
-
router.get name, to: $endpoint, as: as
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
b.report 'recognizing named routes (class endpoints)' do
|
41
|
-
TIMES.times do
|
42
|
-
app.get($named_routes.sample.first)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
##
|
47
|
-
# Lazy
|
48
|
-
#
|
49
|
-
router = Lotus::Router.new
|
50
|
-
app = Rack::MockRequest.new(router)
|
51
|
-
|
52
|
-
$lazy = $lazy.map do |r|
|
53
|
-
[r, r.to_sym]
|
54
|
-
end
|
55
|
-
|
56
|
-
b.report 'generating routes (lazy endpoints)' do
|
57
|
-
$lazy.each do |(name, as)|
|
58
|
-
router.get name, to: name, as: as
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
$lazy.each do |(name, _)|
|
63
|
-
eval "#{ Lotus::Utils::String.new(name).classify } = Class.new($controller)"
|
64
|
-
end
|
65
|
-
|
66
|
-
b.report 'recognizing routes (lazy endpoints)' do
|
67
|
-
TIMES.times do
|
68
|
-
app.get($lazy.sample.first)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
data/benchmarks/resource
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -W0
|
2
|
-
load File.dirname(__FILE__) + '/utils.rb'
|
3
|
-
|
4
|
-
Benchmark.bm(50) do |b|
|
5
|
-
##
|
6
|
-
# Class
|
7
|
-
#
|
8
|
-
router = Lotus::Router.new
|
9
|
-
app = Rack::MockRequest.new(router)
|
10
|
-
|
11
|
-
b.report 'generating resource (class endpoints)' do
|
12
|
-
$resource.each do |r|
|
13
|
-
router.resource r
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
b.report 'recognizing resource (class endpoints)' do
|
18
|
-
TIMES.times do
|
19
|
-
app.get($resource.sample)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
##
|
24
|
-
# Lazy
|
25
|
-
#
|
26
|
-
router = Lotus::Router.new
|
27
|
-
app = Rack::MockRequest.new(router)
|
28
|
-
|
29
|
-
b.report 'generating resource (lazy endpoints)' do
|
30
|
-
$lazy.each do |route|
|
31
|
-
router.resource route
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
$lazy.each do |w|
|
36
|
-
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resource_controller)"
|
37
|
-
end
|
38
|
-
|
39
|
-
b.report 'recognizing routes (lazy endpoints)' do
|
40
|
-
TIMES.times do
|
41
|
-
app.get($lazy.sample)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/benchmarks/resources
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -W0
|
2
|
-
load File.dirname(__FILE__) + '/utils.rb'
|
3
|
-
|
4
|
-
Benchmark.bm(50) do |b|
|
5
|
-
##
|
6
|
-
# Class
|
7
|
-
#
|
8
|
-
router = Lotus::Router.new
|
9
|
-
app = Rack::MockRequest.new(router)
|
10
|
-
|
11
|
-
b.report 'generating resources (class endpoints)' do
|
12
|
-
$resources.each do |r|
|
13
|
-
router.resources r
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
b.report 'recognizing resources (class endpoints)' do
|
18
|
-
TIMES.times do
|
19
|
-
app.get($resources.sample)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
b.report 'recognizing resources with param (class endpoints)' do
|
24
|
-
param = '/23'
|
25
|
-
TIMES.times do
|
26
|
-
app.get($resources.sample + param)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
##
|
31
|
-
# Lazy
|
32
|
-
#
|
33
|
-
router = Lotus::Router.new
|
34
|
-
app = Rack::MockRequest.new(router)
|
35
|
-
|
36
|
-
b.report 'generating resources (lazy endpoints)' do
|
37
|
-
$lazy.each do |r|
|
38
|
-
router.resources r
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
$lazy.each do |w|
|
43
|
-
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resources_controller)"
|
44
|
-
end
|
45
|
-
|
46
|
-
b.report 'recognizing resources (lazy endpoints)' do
|
47
|
-
TIMES.times do
|
48
|
-
app.get($lazy.sample)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
b.report 'recognizing resources with param (lazy endpoints)' do
|
53
|
-
param = '/23'
|
54
|
-
TIMES.times do
|
55
|
-
app.get($lazy.sample + param)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/benchmarks/routes
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby -W0
|
2
|
-
load File.dirname(__FILE__) + '/utils.rb'
|
3
|
-
|
4
|
-
Benchmark.bm(50) do |b|
|
5
|
-
|
6
|
-
##
|
7
|
-
# Callable
|
8
|
-
#
|
9
|
-
router = Lotus::Router.new
|
10
|
-
app = Rack::MockRequest.new(router)
|
11
|
-
|
12
|
-
b.report 'generating routes' do
|
13
|
-
$routes.each do |route|
|
14
|
-
router.get route, to: $endpoint
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
b.report 'recognizing routes' do
|
19
|
-
TIMES.times do
|
20
|
-
app.get($routes.sample)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
##
|
25
|
-
# Class
|
26
|
-
#
|
27
|
-
router = Lotus::Router.new
|
28
|
-
app = Rack::MockRequest.new(router)
|
29
|
-
|
30
|
-
$routes.each do |route|
|
31
|
-
eval "#{ Lotus::Utils::String.new(route).classify } = Class.new($controller)"
|
32
|
-
end
|
33
|
-
|
34
|
-
b.report 'generating routes (class endpoints)' do
|
35
|
-
$routes.each do |route|
|
36
|
-
router.get route, to: route
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
b.report 'recognizing routes (class endpoints)' do
|
41
|
-
TIMES.times do
|
42
|
-
app.get($routes.sample)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
##
|
47
|
-
# Lazy
|
48
|
-
#
|
49
|
-
router = Lotus::Router.new
|
50
|
-
app = Rack::MockRequest.new(router)
|
51
|
-
|
52
|
-
b.report 'generating routes (lazy endpoints)' do
|
53
|
-
$lazy.each do |route|
|
54
|
-
router.get route, to: route
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
$lazy.each do |route|
|
59
|
-
eval "#{ Lotus::Utils::String.new(route).classify } = Class.new($controller)"
|
60
|
-
end
|
61
|
-
|
62
|
-
b.report 'recognizing routes (lazy endpoints)' do
|
63
|
-
TIMES.times do
|
64
|
-
app.get($lazy.sample)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/benchmarks/run.sh
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
benchmarks=$(pwd)/$( dirname "${BASH_SOURCE[0]}" )/*
|
3
|
-
|
4
|
-
for benchmark in $benchmarks
|
5
|
-
do
|
6
|
-
if ! [[ "${benchmark#*.}" =~ (rb|sh)$ ]]; then
|
7
|
-
$benchmark
|
8
|
-
echo "================================================================================================"
|
9
|
-
echo ""
|
10
|
-
fi
|
11
|
-
done
|
data/benchmarks/utils.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
require 'benchmark'
|
3
|
-
require 'lotus/router'
|
4
|
-
|
5
|
-
# head -$((${RANDOM} % `wc -l < /usr/share/dict/words` + 1)) /usr/share/dict/words | tail -1
|
6
|
-
|
7
|
-
BATCH_SIZE = (ENV['BATCH_SIZE'] || 1000 ).to_i
|
8
|
-
TIMES = (ENV['TIMES'] || 100000).to_i
|
9
|
-
|
10
|
-
dict = File.readlines('/usr/share/dict/words').each {|l| l.chomp! }.uniq
|
11
|
-
$routes, $named_routes, $callable, $resource, $resources, $lazy, _ = *dict.each_slice(BATCH_SIZE).to_a
|
12
|
-
|
13
|
-
puts "Loading #{ BATCH_SIZE } routes, calling for #{ TIMES } times...\n"
|
14
|
-
|
15
|
-
class Controller
|
16
|
-
def call(env)
|
17
|
-
[200, {}, ['']]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class ResourceController
|
22
|
-
class Action
|
23
|
-
def call(env)
|
24
|
-
[200, {}, ['']]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
class New < Action; end
|
28
|
-
class Create < Action; end
|
29
|
-
class Show < Action; end
|
30
|
-
class Edit < Action; end
|
31
|
-
class Update < Action; end
|
32
|
-
class Destroy < Action; end
|
33
|
-
end
|
34
|
-
|
35
|
-
class ResourcesController < ResourceController
|
36
|
-
class Index < Action; end
|
37
|
-
end
|
38
|
-
|
39
|
-
$endpoint = ->(env) { [200, {}, ['']] }
|
40
|
-
$controller = Controller
|
41
|
-
$resource_controller = ResourceController
|
42
|
-
$resources_controller = ResourcesController
|
43
|
-
|
44
|
-
$named_routes = $named_routes.map do |r|
|
45
|
-
[r, r.to_sym]
|
46
|
-
end
|
47
|
-
|
48
|
-
$resource.each do |w|
|
49
|
-
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resource_controller)"
|
50
|
-
end
|
51
|
-
|
52
|
-
$resources.each do |w|
|
53
|
-
eval "#{ Lotus::Utils::String.new(w).classify }Controller = Class.new($resources_controller)"
|
54
|
-
end
|
55
|
-
|
56
|
-
GC.start
|
data/test/fixtures.rb
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
class TestEndpoint
|
2
|
-
def call(env)
|
3
|
-
'Hi from TestEndpoint!'
|
4
|
-
end
|
5
|
-
end #TestEndpoint
|
6
|
-
|
7
|
-
class TestController
|
8
|
-
class Show
|
9
|
-
def call(env)
|
10
|
-
'Hi from Test::Show!'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end #TestController
|
14
|
-
|
15
|
-
class TestApp
|
16
|
-
class TestEndpoint
|
17
|
-
def call(env)
|
18
|
-
'Hi from TestApp::TestEndpoint!'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Test2Controller
|
23
|
-
class Show
|
24
|
-
def call(env)
|
25
|
-
'Hi from TestApp::Test2Controller::Show!'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end # TestApp
|
30
|
-
|
31
|
-
class AvatarController
|
32
|
-
class New
|
33
|
-
def call(env)
|
34
|
-
[200, {}, ['Avatar::New']]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class Create
|
39
|
-
def call(env)
|
40
|
-
[200, {}, ['Avatar::Create']]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class Show
|
45
|
-
def call(env)
|
46
|
-
[200, {}, ['Avatar::Show']]
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class Edit
|
51
|
-
def call(env)
|
52
|
-
[200, {}, ['Avatar::Edit']]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class Update
|
57
|
-
def call(env)
|
58
|
-
[200, {}, ['Avatar::Update']]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class Destroy
|
63
|
-
def call(env)
|
64
|
-
[200, {}, ['Avatar::Destroy']]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end # AvatarController
|
68
|
-
|
69
|
-
class ProfileController
|
70
|
-
class Show
|
71
|
-
def call(env)
|
72
|
-
[200, {}, ['Profile::Show']]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class New
|
77
|
-
def call(env)
|
78
|
-
[200, {}, ['Profile::New']]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class Create
|
83
|
-
def call(env)
|
84
|
-
[200, {}, ['Profile::Create']]
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
class Edit
|
89
|
-
def call(env)
|
90
|
-
[200, {}, ['Profile::Edit']]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
class Update
|
95
|
-
def call(env)
|
96
|
-
[200, {}, ['Profile::Update']]
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
class Destroy
|
101
|
-
def call(env)
|
102
|
-
[200, {}, ['Profile::Destroy']]
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
class Activate
|
107
|
-
def call(env)
|
108
|
-
[200, {}, ['Profile::Activate']]
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
class Keys
|
113
|
-
def call(env)
|
114
|
-
[200, {}, ['Profile::Keys']]
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end # ProfileController
|
118
|
-
|
119
|
-
class FlowersController
|
120
|
-
class Index
|
121
|
-
def call(env)
|
122
|
-
[200, {}, ['Flowers::Index']]
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
class New
|
127
|
-
def call(env)
|
128
|
-
[200, {}, ['Flowers::New']]
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class Create
|
133
|
-
def call(env)
|
134
|
-
[200, {}, ['Flowers::Create']]
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
class Show
|
139
|
-
def call(env)
|
140
|
-
[200, {}, ['Flowers::Show ' + env['router.params'][:id]]]
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
class Edit
|
145
|
-
def call(env)
|
146
|
-
[200, {}, ['Flowers::Edit ' + env['router.params'][:id]]]
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
class Update
|
151
|
-
def call(env)
|
152
|
-
[200, {}, ['Flowers::Update ' + env['router.params'][:id]]]
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
class Destroy
|
157
|
-
def call(env)
|
158
|
-
[200, {}, ['Flowers::Destroy ' + env['router.params'][:id]]]
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end # FlowersController
|
162
|
-
|
163
|
-
class KeyboardsController
|
164
|
-
class Index
|
165
|
-
def call(env)
|
166
|
-
[200, {}, ['Keyboards::Index']]
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
class Create
|
171
|
-
def call(env)
|
172
|
-
[200, {}, ['Keyboards::Create']]
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class Edit
|
177
|
-
def call(env)
|
178
|
-
[200, {}, ['Keyboards::Edit ' + env['router.params'][:id]]]
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
class Search
|
183
|
-
def call(env)
|
184
|
-
[200, {}, ['Keyboards::Search']]
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
class Screenshot
|
189
|
-
def call(env)
|
190
|
-
[200, {}, ['Keyboards::Screenshot ' + env['router.params'][:id]]]
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end # KeyboardsController
|