pendragon 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -16
- data/README.md +19 -10
- data/lib/pendragon/{compile_helpers.rb → engine/compiler.rb} +19 -11
- data/lib/pendragon/engine/recognizer.rb +65 -0
- data/lib/pendragon/padrino/ext/class_methods.rb +9 -1
- data/lib/pendragon/padrino/router.rb +6 -1
- data/lib/pendragon/router.rb +18 -68
- data/lib/pendragon/version.rb +1 -1
- data/lib/pendragon.rb +18 -0
- data/test/compile_helper.rb +1 -3
- data/test/helper.rb +29 -25
- data/test/pendragon_configuration.rb +6 -5
- data/test/pendragon_test.rb +3 -5
- metadata +18 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96b558eec1e2524045fcd153be5bca8bb159ffdd
|
4
|
+
data.tar.gz: b2411809a3ccb47d6d9a46c162c9611b9bddffbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7152a62fffeb920032d0ee6699183c662e18aa138567e638506fd8d6158d53aa47884b9b971c3ceadaa693380204c5b9f8c3d037891be37cdf01c5a4801f47bb
|
7
|
+
data.tar.gz: 8a7dcf1502c0b4b9febec24efd7f96aff8f0f644d492a44f0883cd7b0da562014ccf6c089f07d5f351c67b98dc4cb1267d9f96c37d672801a66ce5df5f9c7158
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pendragon (0.
|
4
|
+
pendragon (0.4.0)
|
5
5
|
mustermann (= 0.2.0)
|
6
6
|
rack (>= 1.3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (4.
|
12
|
-
i18n (~> 0.6, >= 0.6.
|
13
|
-
|
14
|
-
|
11
|
+
activesupport (4.1.1)
|
12
|
+
i18n (~> 0.6, >= 0.6.9)
|
13
|
+
json (~> 1.7, >= 1.7.7)
|
14
|
+
minitest (~> 5.1)
|
15
15
|
thread_safe (~> 0.1)
|
16
|
-
tzinfo (~>
|
17
|
-
atomic (1.1.14)
|
16
|
+
tzinfo (~> 1.1)
|
18
17
|
haml (4.0.5)
|
19
18
|
tilt
|
20
19
|
http_router (0.11.1)
|
21
20
|
rack (>= 1.0.0)
|
22
21
|
url_mount (~> 0.2.1)
|
23
22
|
i18n (0.6.9)
|
23
|
+
json (1.8.1)
|
24
24
|
metaclass (0.0.4)
|
25
|
-
minitest (
|
26
|
-
mocha (1.
|
25
|
+
minitest (5.3.4)
|
26
|
+
mocha (1.1.0)
|
27
27
|
metaclass (~> 0.0.1)
|
28
|
-
multi_json (1.8.4)
|
29
28
|
mustermann (0.2.0)
|
30
29
|
padrino-core (0.12.0.rc3)
|
31
30
|
activesupport (>= 3.1)
|
@@ -35,20 +34,20 @@ GEM
|
|
35
34
|
thor (~> 0.17.0)
|
36
35
|
tilt (~> 1.4.1)
|
37
36
|
rack (1.5.2)
|
38
|
-
rack-protection (1.5.
|
37
|
+
rack-protection (1.5.3)
|
39
38
|
rack
|
40
39
|
rack-test (0.6.2)
|
41
40
|
rack (>= 1.0)
|
42
|
-
rake (10.
|
43
|
-
sinatra (1.4.
|
41
|
+
rake (10.3.2)
|
42
|
+
sinatra (1.4.5)
|
44
43
|
rack (~> 1.4)
|
45
44
|
rack-protection (~> 1.4)
|
46
45
|
tilt (~> 1.3, >= 1.3.4)
|
47
46
|
thor (0.17.0)
|
48
|
-
thread_safe (0.
|
49
|
-
atomic
|
47
|
+
thread_safe (0.3.3)
|
50
48
|
tilt (1.4.1)
|
51
|
-
tzinfo (
|
49
|
+
tzinfo (1.1.0)
|
50
|
+
thread_safe (~> 0.1)
|
52
51
|
url_mount (0.2.1)
|
53
52
|
rack
|
54
53
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Pendragon
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/namusyaka/pendragon.
|
3
|
+
[![Build Status](https://travis-ci.org/namusyaka/pendragon.svg?branch=master)](https://travis-ci.org/namusyaka/pendragon) [![Gem Version](https://badge.fury.io/rb/pendragon.svg)](http://badge.fury.io/rb/pendragon)
|
4
4
|
|
5
5
|
Pendragon provides an HTTP router for use in Rack and Padrino.
|
6
6
|
As a Rack application, it makes it easy to define complicated routing.
|
@@ -37,7 +37,7 @@ Depends on [rack](https://github.com/rack/rack) and [mustermann](https://github.
|
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
# Performance will be improved!
|
40
|
-
Pendragon.
|
40
|
+
Pendragon.new do |config|
|
41
41
|
config.enable_compiler = true
|
42
42
|
end
|
43
43
|
```
|
@@ -52,12 +52,24 @@ Pendragon.new do
|
|
52
52
|
get("/"){ "hey" }
|
53
53
|
end
|
54
54
|
|
55
|
-
Pendragon.
|
55
|
+
pendragon = Pendragon.new do |config|
|
56
56
|
config.auto_rack_format = false
|
57
57
|
end
|
58
58
|
# Disable the param
|
59
|
-
|
60
|
-
|
59
|
+
pendragon.get("/"){ [200, {"Content-Type" => "text/html;charset=utf-8"}, ["hey"]] }
|
60
|
+
```
|
61
|
+
|
62
|
+
#### Deprecated
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# Global configuration style is deprecated since 0.5.0
|
66
|
+
Pendragon.configure do |config|
|
67
|
+
config.enable_compiler = true
|
68
|
+
end
|
69
|
+
|
70
|
+
# Please use new syntax.
|
71
|
+
pendragon = Pendragon.new do |config|
|
72
|
+
config.enable_compiler = true
|
61
73
|
end
|
62
74
|
```
|
63
75
|
|
@@ -225,12 +237,9 @@ require 'pendragon/padrino'
|
|
225
237
|
|
226
238
|
class App < Padrino::Application
|
227
239
|
register Pendragon::Padrino
|
228
|
-
|
229
|
-
##
|
240
|
+
|
230
241
|
# Also, your app's performance will be improved by using compiler mode.
|
231
|
-
|
232
|
-
# config.enable_compiler = true
|
233
|
-
# end
|
242
|
+
set :pendragon, enable_compiler: true
|
234
243
|
|
235
244
|
get :index do
|
236
245
|
"hello pendragon!"
|
@@ -1,6 +1,24 @@
|
|
1
|
+
require 'pendragon/engine/recognizer'
|
1
2
|
|
2
3
|
module Pendragon
|
3
|
-
|
4
|
+
class Compiler < Recognizer
|
5
|
+
def initialize(routes)
|
6
|
+
@routes = routes
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(request)
|
10
|
+
compile! unless compiled?
|
11
|
+
pattern, verb, params = parse_request(request)
|
12
|
+
raise_exception(400) unless valid_verb?(verb)
|
13
|
+
candidacies = match_with(pattern)
|
14
|
+
raise_exception(404) if candidacies.empty?
|
15
|
+
candidacies, allows = candidacies.partition{|route| route.verb == verb }
|
16
|
+
raise_exception(405, verbs: allows.map(&:verb)) if candidacies.empty?
|
17
|
+
candidacies.map{|route| [route, params_for(route, pattern, params)]}
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
4
22
|
def compile!
|
5
23
|
return if compiled?
|
6
24
|
@regexps = @routes.map.with_index do |route, index|
|
@@ -23,16 +41,6 @@ module Pendragon
|
|
23
41
|
!!@regexps
|
24
42
|
end
|
25
43
|
|
26
|
-
def recognize_by_compiling_regexp(request)
|
27
|
-
prepare! unless prepared?
|
28
|
-
pattern, verb, params = parse_request(request)
|
29
|
-
candidacies = match_with(pattern)
|
30
|
-
raise_exception(404) if candidacies.empty?
|
31
|
-
candidacies, allows = candidacies.partition{|route| route.verb == verb }
|
32
|
-
raise_exception(405, verbs: allows.map(&:verb)) if candidacies.empty?
|
33
|
-
candidacies.map{|route| [route, params_for(route, pattern, params)]}
|
34
|
-
end
|
35
|
-
|
36
44
|
def match_with(pattern)
|
37
45
|
offset = 0
|
38
46
|
conditions = [pattern]
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Pendragon
|
2
|
+
class Recognizer
|
3
|
+
def initialize(routes)
|
4
|
+
@routes = routes
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(request)
|
8
|
+
pattern, verb, params = parse_request(request)
|
9
|
+
raise_exception(400) unless valid_verb?(verb)
|
10
|
+
fetch(pattern, verb){|route| [route, params_for(route, pattern, params)] }
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# @!visibility private
|
16
|
+
def params_for(route, pattern, params)
|
17
|
+
route.params(pattern, params)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @!visibility private
|
21
|
+
def valid_verb?(verb)
|
22
|
+
Pendragon::HTTP_VERBS.include?(verb.downcase.to_sym)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @!visibility private
|
26
|
+
def fetch(pattern, verb)
|
27
|
+
_routes = @routes.select{|route| route.match(pattern) }
|
28
|
+
raise_exception(404) if _routes.empty?
|
29
|
+
result = _routes.map{|route| yield(route) if verb == route.verb }.compact
|
30
|
+
raise_exception(405, :verbs => _routes.map(&:verb)) if result.empty?
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
# @!visibility private
|
35
|
+
def parse_request(request)
|
36
|
+
if request.is_a?(Hash)
|
37
|
+
[request['PATH_INFO'], request['REQUEST_METHOD'].downcase.to_sym, {}]
|
38
|
+
else
|
39
|
+
[request.path_info, request.request_method.downcase.to_sym, parse_request_params(request.params)]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# @!visibility private
|
44
|
+
def parse_request_params(params)
|
45
|
+
params.inject({}) do |result, entry|
|
46
|
+
result[entry[0].to_sym] = entry[1]
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# @!visibility private
|
52
|
+
def raise_exception(error_code, options = {})
|
53
|
+
raise ->(error_code) {
|
54
|
+
case error_code
|
55
|
+
when 400
|
56
|
+
BadRequest
|
57
|
+
when 404
|
58
|
+
NotFound
|
59
|
+
when 405
|
60
|
+
MethodNotAllowed.new(options[:verbs])
|
61
|
+
end
|
62
|
+
}.(error_code)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -5,7 +5,15 @@ module Pendragon
|
|
5
5
|
ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2} unless defined?(ROUTE_PRIORITY)
|
6
6
|
|
7
7
|
def router
|
8
|
-
@router
|
8
|
+
unless @router
|
9
|
+
@router = ::Pendragon::Padrino::Router.new
|
10
|
+
@router.configuration = Pendragon::Configuration.new
|
11
|
+
if settings.respond_to?(:pendragon) && settings.pendragon.instance_of?(Hash)
|
12
|
+
settings.pendragon.each_pair do |key, value|
|
13
|
+
@router.configuration.send("#{key}=", value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
9
17
|
block_given? ? yield(@router) : @router
|
10
18
|
end
|
11
19
|
|
@@ -3,6 +3,8 @@ require 'pendragon' unless defined?(Pendragon::Router)
|
|
3
3
|
module Pendragon
|
4
4
|
module Padrino
|
5
5
|
class Router < Pendragon::Router
|
6
|
+
attr_accessor :configuration
|
7
|
+
|
6
8
|
def add(verb, path, options = {}, &block)
|
7
9
|
route = Route.new(path, verb, options, &block)
|
8
10
|
route.path_for_generation = options[:path_for_generation] if options[:path_for_generation]
|
@@ -13,7 +15,6 @@ module Pendragon
|
|
13
15
|
|
14
16
|
def call(env)
|
15
17
|
request = Rack::Request.new(env)
|
16
|
-
raise_exception(400) unless valid_verb?(request.request_method)
|
17
18
|
[200, {}, recognize(request)]
|
18
19
|
rescue BadRequest, NotFound, MethodNotAllowed
|
19
20
|
$!.call
|
@@ -24,6 +25,10 @@ module Pendragon
|
|
24
25
|
matcher.mustermann? ? matcher.expand(params) : route.path_for_generation
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
def configuration
|
30
|
+
@configuration || Pendragon::Configuration.new
|
31
|
+
end
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
data/lib/pendragon/router.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'pendragon/route'
|
2
2
|
require 'pendragon/matcher'
|
3
3
|
require 'pendragon/error_handler'
|
4
|
-
require 'pendragon/compile_helpers'
|
5
4
|
require 'pendragon/configuration'
|
5
|
+
require 'pendragon/engine/compiler'
|
6
6
|
require 'rack'
|
7
7
|
|
8
8
|
module Pendragon
|
@@ -15,9 +15,9 @@ module Pendragon
|
|
15
15
|
# Possible to pass the block
|
16
16
|
#
|
17
17
|
# @example with a block
|
18
|
-
# app = Pendragon::Router.new do
|
19
|
-
#
|
20
|
-
#
|
18
|
+
# app = Pendragon::Router.new do |config|
|
19
|
+
# config.enable_compiler = true
|
20
|
+
# config.auto_rack_format = false
|
21
21
|
# end
|
22
22
|
#
|
23
23
|
# @example with base style
|
@@ -26,14 +26,20 @@ module Pendragon
|
|
26
26
|
# app.post("/"){ "hello post!" }
|
27
27
|
def initialize(&block)
|
28
28
|
reset!
|
29
|
-
|
29
|
+
if block_given?
|
30
|
+
if block.arity.zero?
|
31
|
+
instance_eval(&block)
|
32
|
+
else
|
33
|
+
@configuration = Configuration.new
|
34
|
+
block.call(configuration)
|
35
|
+
end
|
36
|
+
end
|
30
37
|
end
|
31
38
|
|
32
39
|
# Finds the routes if request method is valid
|
33
40
|
# @return the Rack style response
|
34
41
|
def call(env)
|
35
42
|
request = Rack::Request.new(env)
|
36
|
-
raise_exception(400) unless valid_verb?(request.request_method)
|
37
43
|
recognize(request).each do |route, params|
|
38
44
|
catch(:pass){ return invoke(route, params) }
|
39
45
|
end
|
@@ -43,7 +49,7 @@ module Pendragon
|
|
43
49
|
|
44
50
|
def invoke(route, params)
|
45
51
|
response = route.arity != 0 ? route.call(params) : route.call
|
46
|
-
return response unless
|
52
|
+
return response unless configuration.auto_rack_format?
|
47
53
|
status = route.options[:status] || 200
|
48
54
|
header = {'Content-Type' => 'text/html;charset=utf-8'}.merge(route.options[:header] || {})
|
49
55
|
[status, header, Array(response)]
|
@@ -78,16 +84,7 @@ module Pendragon
|
|
78
84
|
def prepare!
|
79
85
|
@prepared = true
|
80
86
|
@routes.sort_by!(&:order)
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
# Setups the compiler by using CompileHelpers
|
85
|
-
# @see Pendragon::CompileHelpers
|
86
|
-
def self.setup_compiler!
|
87
|
-
include CompileHelpers
|
88
|
-
alias_method :old_recognize, :recognize
|
89
|
-
alias_method :recognize, :recognize_by_compiling_regexp
|
90
|
-
true
|
87
|
+
@engine = (configuration.enable_compiler? ? Compiler : Recognizer).new(routes)
|
91
88
|
end
|
92
89
|
|
93
90
|
# @return [Boolean] the router is already prepared?
|
@@ -105,8 +102,7 @@ module Pendragon
|
|
105
102
|
# @return [Array]
|
106
103
|
def recognize(request)
|
107
104
|
prepare! unless prepared?
|
108
|
-
|
109
|
-
fetch(pattern, verb){|route| [route, params_for(route, pattern, params)] }
|
105
|
+
@engine.call(request)
|
110
106
|
end
|
111
107
|
|
112
108
|
# Recognizes a given path
|
@@ -130,43 +126,11 @@ module Pendragon
|
|
130
126
|
end
|
131
127
|
end
|
132
128
|
|
133
|
-
|
134
|
-
|
135
|
-
# @!visibility private
|
136
|
-
def valid_verb?(verb)
|
137
|
-
Pendragon::HTTP_VERBS.include?(verb.downcase.to_sym)
|
138
|
-
end
|
139
|
-
|
140
|
-
# @!visibility private
|
141
|
-
def fetch(pattern, verb)
|
142
|
-
_routes = routes.select{|route| route.match(pattern) }
|
143
|
-
raise_exception(404) if _routes.empty?
|
144
|
-
result = _routes.map{|route| yield(route) if verb == route.verb }.compact
|
145
|
-
raise_exception(405, :verbs => _routes.map(&:verb)) if result.empty?
|
146
|
-
result
|
147
|
-
end
|
148
|
-
|
149
|
-
# @!visibility private
|
150
|
-
def parse_request(request)
|
151
|
-
if request.is_a?(Hash)
|
152
|
-
[request['PATH_INFO'], request['REQUEST_METHOD'].downcase.to_sym, {}]
|
153
|
-
else
|
154
|
-
[request.path_info, request.request_method.downcase.to_sym, parse_request_params(request.params)]
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
# @!visibility private
|
159
|
-
def parse_request_params(params)
|
160
|
-
params.inject({}) do |result, entry|
|
161
|
-
result[entry[0].to_sym] = entry[1]
|
162
|
-
result
|
163
|
-
end
|
129
|
+
def configuration
|
130
|
+
@configuration || Pendragon.configuration
|
164
131
|
end
|
165
132
|
|
166
|
-
|
167
|
-
def params_for(route, pattern, params)
|
168
|
-
route.params(pattern, params)
|
169
|
-
end
|
133
|
+
private
|
170
134
|
|
171
135
|
# @!visibility private
|
172
136
|
# @example
|
@@ -192,19 +156,5 @@ module Pendragon
|
|
192
156
|
end
|
193
157
|
raise InvalidRouteException
|
194
158
|
end
|
195
|
-
|
196
|
-
# @!visibility private
|
197
|
-
def raise_exception(error_code, options = {})
|
198
|
-
raise ->(error_code) {
|
199
|
-
case error_code
|
200
|
-
when 400
|
201
|
-
BadRequest
|
202
|
-
when 404
|
203
|
-
NotFound
|
204
|
-
when 405
|
205
|
-
MethodNotAllowed.new(options[:verbs])
|
206
|
-
end
|
207
|
-
}.(error_code)
|
208
|
-
end
|
209
159
|
end
|
210
160
|
end
|
data/lib/pendragon/version.rb
CHANGED
data/lib/pendragon.rb
CHANGED
@@ -12,6 +12,7 @@ module Pendragon
|
|
12
12
|
Router.new(&block)
|
13
13
|
end
|
14
14
|
|
15
|
+
# @deprecated
|
15
16
|
# Yields Pendragon configuration block
|
16
17
|
# @example
|
17
18
|
# Pendragon.configure do |config|
|
@@ -19,18 +20,35 @@ module Pendragon
|
|
19
20
|
# end
|
20
21
|
# @see Pendragon::Configuration
|
21
22
|
def configure(&block)
|
23
|
+
configuration_warning(:configure)
|
22
24
|
block.call(configuration) if block_given?
|
23
25
|
configuration
|
24
26
|
end
|
25
27
|
|
28
|
+
# @deprecated
|
26
29
|
# Returns Pendragon configuration
|
27
30
|
def configuration
|
31
|
+
configuration_warning(:configuration)
|
28
32
|
@configuration ||= Configuration.new
|
29
33
|
end
|
30
34
|
|
35
|
+
# @deprecated
|
31
36
|
# Resets Pendragon configuration
|
32
37
|
def reset_configuration!
|
33
38
|
@configuration = nil
|
34
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def configuration_warning(method)
|
44
|
+
warn <<-WARN
|
45
|
+
Pendragon.#{method} is deprecated because it isn't thread-safe.
|
46
|
+
Please use new syntax.
|
47
|
+
Pendragon.new do |config|
|
48
|
+
config.auto_rack_format = false
|
49
|
+
config.enable_compiler = true
|
50
|
+
end
|
51
|
+
WARN
|
52
|
+
end
|
35
53
|
end
|
36
54
|
end
|
data/test/compile_helper.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -3,7 +3,6 @@ ENV['PADRINO_ENV'] = 'test'
|
|
3
3
|
PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT)
|
4
4
|
require File.expand_path('../../lib/pendragon', __FILE__)
|
5
5
|
|
6
|
-
require 'minitest/unit'
|
7
6
|
require 'minitest/autorun'
|
8
7
|
require 'minitest/spec'
|
9
8
|
require 'mocha/setup'
|
@@ -22,16 +21,18 @@ end
|
|
22
21
|
class MiniTest::Spec
|
23
22
|
include Rack::Test::Methods
|
24
23
|
|
25
|
-
def pendragon
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
def pendragon(&block)
|
25
|
+
if !block_given? && defined?(ENABLE_COMPILER)
|
26
|
+
block = Proc.new do |config|
|
27
|
+
config.enable_compiler = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@app = Pendragon.new(&block)
|
31
31
|
end
|
32
32
|
|
33
33
|
def mock_app(base = nil, &block)
|
34
34
|
@app = Sinatra.new(base || ::Padrino::Application, &block)
|
35
|
+
@app.class_eval{ set :pendragon, :enable_compiler => defined?(ENABLE_COMPILER) }
|
35
36
|
end
|
36
37
|
|
37
38
|
def app
|
@@ -64,24 +65,27 @@ class MiniTest::Spec
|
|
64
65
|
end
|
65
66
|
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
68
|
+
if defined?(MiniTest::Unit.output)
|
69
|
+
class ColoredIO
|
70
|
+
def initialize(io)
|
71
|
+
@io = io
|
72
|
+
end
|
73
|
+
|
74
|
+
def print(o)
|
75
|
+
case o
|
76
|
+
when "." then @io.send(:print, o.colorize(:green))
|
77
|
+
when "E" then @io.send(:print, o.colorize(:red))
|
78
|
+
when "F" then @io.send(:print, o.colorize(:yellow))
|
79
|
+
when "S" then @io.send(:print, o.colorize(:magenta))
|
80
|
+
else @io.send(:print, o)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def puts(*o)
|
85
|
+
super
|
79
86
|
end
|
80
87
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
88
|
+
MiniTest::Unit.output = ColoredIO.new($stdout)
|
89
|
+
else
|
90
|
+
require 'minitest/pride'
|
85
91
|
end
|
86
|
-
|
87
|
-
MiniTest::Unit.output = ColoredIO.new($stdout)
|
@@ -3,19 +3,20 @@ $:.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'helper'
|
4
4
|
|
5
5
|
describe Pendragon::Configuration do
|
6
|
-
setup
|
7
|
-
|
6
|
+
setup do
|
7
|
+
@pendragon = pendragon{|config| }
|
8
|
+
end
|
8
9
|
|
9
10
|
describe "auto_rack_format" do
|
10
11
|
should "set `true` as default value" do
|
11
12
|
@pendragon.get("/"){ "hey" }
|
12
13
|
get "/"
|
13
14
|
assert_equal "hey", body
|
14
|
-
assert_equal true,
|
15
|
+
assert_equal true, @pendragon.configuration.auto_rack_format?
|
15
16
|
end
|
16
17
|
|
17
18
|
should "not serialize for rack format if `auto_rack_format` is false" do
|
18
|
-
|
19
|
+
@pendragon = pendragon do |config|
|
19
20
|
config.auto_rack_format = false
|
20
21
|
end
|
21
22
|
|
@@ -25,7 +26,7 @@ describe Pendragon::Configuration do
|
|
25
26
|
@pendragon.post("/"){ [200, {'Content-Type' => 'text/html;charset=utf-8'}, ["hey"]] }
|
26
27
|
post "/"
|
27
28
|
assert_equal "hey", body
|
28
|
-
assert_equal false,
|
29
|
+
assert_equal false, @pendragon.configuration.auto_rack_format?
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
data/test/pendragon_test.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'helper'
|
4
4
|
|
5
5
|
describe Pendragon do
|
6
|
-
setup{ @pendragon = pendragon }
|
6
|
+
setup{ @pendragon = pendragon{|config| config.enable_compiler = defined?(ENABLE_COMPILER) } }
|
7
7
|
|
8
8
|
describe "normal routing" do
|
9
9
|
before(:each){ @pendragon.reset! }
|
@@ -185,10 +185,8 @@ describe Pendragon do
|
|
185
185
|
|
186
186
|
describe "#new allows block" do
|
187
187
|
should "#new support for block." do
|
188
|
-
|
189
|
-
|
190
|
-
bar = add(:post, "/", :name => :bar){"bar"}
|
191
|
-
end
|
188
|
+
foo = @pendragon.add(:get, "/", :name => :foo){"foo"}
|
189
|
+
bar = @pendragon.add(:post, "/", :name => :bar){"bar"}
|
192
190
|
get("/")
|
193
191
|
assert_equal "foo", body
|
194
192
|
post("/")
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pendragon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- namusyaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 1.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -42,56 +42,56 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.8.7
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.8.7
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack-test
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.5.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.5.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: mocha
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.10.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.10.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: haml
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
@@ -114,15 +114,16 @@ executables: []
|
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files: []
|
116
116
|
files:
|
117
|
-
-
|
117
|
+
- .travis.yml
|
118
118
|
- Gemfile
|
119
119
|
- Gemfile.lock
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
122
|
- config.ru
|
123
123
|
- lib/pendragon.rb
|
124
|
-
- lib/pendragon/compile_helpers.rb
|
125
124
|
- lib/pendragon/configuration.rb
|
125
|
+
- lib/pendragon/engine/compiler.rb
|
126
|
+
- lib/pendragon/engine/recognizer.rb
|
126
127
|
- lib/pendragon/error_handler.rb
|
127
128
|
- lib/pendragon/matcher.rb
|
128
129
|
- lib/pendragon/padrino.rb
|
@@ -149,17 +150,17 @@ require_paths:
|
|
149
150
|
- lib
|
150
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
152
|
requirements:
|
152
|
-
- -
|
153
|
+
- - '>='
|
153
154
|
- !ruby/object:Gem::Version
|
154
155
|
version: '0'
|
155
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
157
|
requirements:
|
157
|
-
- -
|
158
|
+
- - '>='
|
158
159
|
- !ruby/object:Gem::Version
|
159
160
|
version: '0'
|
160
161
|
requirements: []
|
161
162
|
rubyforge_project:
|
162
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.0.14
|
163
164
|
signing_key:
|
164
165
|
specification_version: 4
|
165
166
|
summary: Provides an HTTP router for use in Rack and Padrino.
|