pendragon 0.5.1 → 0.6.0
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/Gemfile.lock +27 -27
- data/README.md +11 -0
- data/lib/pendragon/configuration.rb +5 -0
- data/lib/pendragon/engine/compiler.rb +3 -2
- data/lib/pendragon/engine/recognizer.rb +1 -1
- data/lib/pendragon/padrino/ext/class_methods.rb +2 -2
- data/lib/pendragon/padrino/router.rb +1 -1
- data/lib/pendragon/router.rb +18 -6
- data/lib/pendragon/version.rb +1 -1
- data/test/padrino_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7cbea66f8dd29316768cfb0fe023d1406a8b64
|
4
|
+
data.tar.gz: 0e01b51a0a24b2ee596bf4f01d228a9885b49269
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2010774c84e8aa9c33c4190c69e068b9e1d318dada14316dcaa4a3550a7363544626a2d77a791269ec0ec86426bd9c7542f5013f96340c020afdba74027d8cbe
|
7
|
+
data.tar.gz: 62dd9579a534ded3447bc6de68503cfcd6e70e56db1df11802c3bcb1abc26ac5274e332b083b33b0c96033e434427cac2e9f38bd70ff114de4a2228811da14ee
|
data/Gemfile.lock
CHANGED
@@ -8,7 +8,7 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (4.1.
|
11
|
+
activesupport (4.1.5)
|
12
12
|
i18n (~> 0.6, >= 0.6.9)
|
13
13
|
json (~> 1.7, >= 1.7.7)
|
14
14
|
minitest (~> 5.1)
|
@@ -31,39 +31,39 @@ GEM
|
|
31
31
|
metaclass (~> 0.0.1)
|
32
32
|
moneta (0.7.20)
|
33
33
|
mustermann (0.2.0)
|
34
|
-
padrino (0.12.
|
35
|
-
padrino-admin (= 0.12.
|
36
|
-
padrino-cache (= 0.12.
|
37
|
-
padrino-core (= 0.12.
|
38
|
-
padrino-gen (= 0.12.
|
39
|
-
padrino-helpers (= 0.12.
|
40
|
-
padrino-mailer (= 0.12.
|
41
|
-
padrino-support (= 0.12.
|
42
|
-
padrino-admin (0.12.
|
43
|
-
padrino-core (= 0.12.
|
44
|
-
padrino-helpers (= 0.12.
|
45
|
-
padrino-cache (0.12.
|
34
|
+
padrino (0.12.3)
|
35
|
+
padrino-admin (= 0.12.3)
|
36
|
+
padrino-cache (= 0.12.3)
|
37
|
+
padrino-core (= 0.12.3)
|
38
|
+
padrino-gen (= 0.12.3)
|
39
|
+
padrino-helpers (= 0.12.3)
|
40
|
+
padrino-mailer (= 0.12.3)
|
41
|
+
padrino-support (= 0.12.3)
|
42
|
+
padrino-admin (0.12.3)
|
43
|
+
padrino-core (= 0.12.3)
|
44
|
+
padrino-helpers (= 0.12.3)
|
45
|
+
padrino-cache (0.12.3)
|
46
46
|
moneta (~> 0.7.0)
|
47
|
-
padrino-core (= 0.12.
|
48
|
-
padrino-helpers (= 0.12.
|
49
|
-
padrino-core (0.12.
|
47
|
+
padrino-core (= 0.12.3)
|
48
|
+
padrino-helpers (= 0.12.3)
|
49
|
+
padrino-core (0.12.3)
|
50
50
|
activesupport (>= 3.1)
|
51
51
|
http_router (~> 0.11.0)
|
52
|
-
padrino-support (= 0.12.
|
52
|
+
padrino-support (= 0.12.3)
|
53
53
|
rack-protection (>= 1.5.0)
|
54
54
|
sinatra (~> 1.4.2)
|
55
|
-
thor (~> 0.18
|
56
|
-
padrino-gen (0.12.
|
55
|
+
thor (~> 0.18)
|
56
|
+
padrino-gen (0.12.3)
|
57
57
|
bundler (~> 1.0)
|
58
|
-
padrino-core (= 0.12.
|
59
|
-
padrino-helpers (0.12.
|
58
|
+
padrino-core (= 0.12.3)
|
59
|
+
padrino-helpers (0.12.3)
|
60
60
|
i18n (~> 0.6, >= 0.6.7)
|
61
|
-
padrino-support (= 0.12.
|
61
|
+
padrino-support (= 0.12.3)
|
62
62
|
tilt (~> 1.4.1)
|
63
|
-
padrino-mailer (0.12.
|
63
|
+
padrino-mailer (0.12.3)
|
64
64
|
mail (~> 2.5.3)
|
65
|
-
padrino-core (= 0.12.
|
66
|
-
padrino-support (0.12.
|
65
|
+
padrino-core (= 0.12.3)
|
66
|
+
padrino-support (0.12.3)
|
67
67
|
activesupport (>= 3.1)
|
68
68
|
polyglot (0.3.5)
|
69
69
|
rack (1.5.2)
|
@@ -76,13 +76,13 @@ GEM
|
|
76
76
|
rack (~> 1.4)
|
77
77
|
rack-protection (~> 1.4)
|
78
78
|
tilt (~> 1.3, >= 1.3.4)
|
79
|
-
thor (0.
|
79
|
+
thor (0.19.1)
|
80
80
|
thread_safe (0.3.4)
|
81
81
|
tilt (1.4.1)
|
82
82
|
treetop (1.4.15)
|
83
83
|
polyglot
|
84
84
|
polyglot (>= 0.3.1)
|
85
|
-
tzinfo (1.2.
|
85
|
+
tzinfo (1.2.2)
|
86
86
|
thread_safe (~> 0.1)
|
87
87
|
url_mount (0.2.1)
|
88
88
|
rack
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ Depends on [rack](https://github.com/rack/rack) and [mustermann](https://github.
|
|
32
32
|
|:---------------|:------|:------|:-------------------------|
|
33
33
|
|enable_compiler |boolean|false|The performance will be improved. However, it will increase the first load time.|
|
34
34
|
|auto_rack_format|boolean|true|If disable this param, the block of route should return the response of valid rack format.|
|
35
|
+
|lock |boolean|false|If you enable this option, all requests to synchronize on a mutex lock|
|
35
36
|
|
36
37
|
#### `enable_compiler`
|
37
38
|
|
@@ -59,6 +60,16 @@ end
|
|
59
60
|
pendragon.get("/"){ [200, {"Content-Type" => "text/html;charset=utf-8"}, ["hey"]] }
|
60
61
|
```
|
61
62
|
|
63
|
+
#### `lock`
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
pendragon = Pendragon.new do |config|
|
67
|
+
config.lock = true
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
If you use pendragon in threaded environment, you should enable this option to avoid compiling all routes again and again.
|
72
|
+
|
62
73
|
#### Deprecated
|
63
74
|
|
64
75
|
```ruby
|
@@ -23,10 +23,15 @@ module Pendragon
|
|
23
23
|
# @see Pendragon::Router#invoke
|
24
24
|
attr_boolean_accessor :auto_rack_format
|
25
25
|
|
26
|
+
# Enables to lock for threaded environment.
|
27
|
+
# If you enable this option, all requests to synchronize on a mutex lock
|
28
|
+
attr_boolean_accessor :lock
|
29
|
+
|
26
30
|
# Constructs an instance of Pendragon::Configuration
|
27
31
|
def initialize
|
28
32
|
@enable_compiler = false
|
29
33
|
@auto_rack_format = true
|
34
|
+
@lock = false
|
30
35
|
end
|
31
36
|
|
32
37
|
# Returns an instance variable
|
@@ -17,7 +17,7 @@ module Pendragon
|
|
17
17
|
# @raise [Pendragon::BadRequest] raised if request is bad request
|
18
18
|
# @raise [Pendragon::NotFound] raised if cannot find routes that match with pattern
|
19
19
|
# @raise [Pendragon::MethodNotAllowed] raised if routes can be find and do not match with verb
|
20
|
-
# @return [Array] The return value will be something like [Pendragon::Route, Hash]
|
20
|
+
# @return [Array] The return value will be something like [[Pendragon::Route, Hash], ..]
|
21
21
|
def call(request)
|
22
22
|
compile! unless compiled?
|
23
23
|
pattern, verb, params = parse_request(request)
|
@@ -39,6 +39,7 @@ module Pendragon
|
|
39
39
|
/(?<_#{index}>#{regexp})/
|
40
40
|
end
|
41
41
|
@regexps = compile(@regexps)
|
42
|
+
@compiled = true
|
42
43
|
end
|
43
44
|
|
44
45
|
# @!visibility private
|
@@ -51,7 +52,7 @@ module Pendragon
|
|
51
52
|
|
52
53
|
# @!visibility private
|
53
54
|
def compiled?
|
54
|
-
!!@
|
55
|
+
!!@compiled
|
55
56
|
end
|
56
57
|
|
57
58
|
# @!visibility private
|
@@ -12,7 +12,7 @@ module Pendragon
|
|
12
12
|
@routes = routes
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# Recognizes routes, and returns them
|
16
16
|
# @param [Rack::Request] request
|
17
17
|
# @raise [Pendragon::BadRequest] raised if request is bad request
|
18
18
|
# @raise [Pendragon::NotFound] raised if cannot find routes that match with pattern
|
@@ -198,8 +198,8 @@ module Pendragon
|
|
198
198
|
end
|
199
199
|
|
200
200
|
# Now we need to parse our 'parent' params and parent scope.
|
201
|
-
if !absolute_map and parent_params = options.delete(:parent) || @
|
202
|
-
parent_params = (Array(@
|
201
|
+
if !absolute_map and parent_params = options.delete(:parent) || @_parent
|
202
|
+
parent_params = (Array(@_parent) + Array(parent_params)).uniq
|
203
203
|
path = process_path_for_parent_params(path, parent_params)
|
204
204
|
end
|
205
205
|
|
@@ -21,7 +21,7 @@ module Pendragon
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def path(name, *args)
|
24
|
-
|
24
|
+
extract_with(name, *args) do |route, params, matcher|
|
25
25
|
matcher.mustermann? ? matcher.expand(params) : route.path_for_generation
|
26
26
|
end
|
27
27
|
end
|
data/lib/pendragon/router.rb
CHANGED
@@ -21,6 +21,9 @@ module Pendragon
|
|
21
21
|
# The accessors are useful to access from Pendragon::Route
|
22
22
|
attr_accessor :current, :routes
|
23
23
|
|
24
|
+
# @see Pendragon::Configuration#lock?
|
25
|
+
@@mutex = Mutex.new
|
26
|
+
|
24
27
|
# Constructs a new instance of Pendragon::Router
|
25
28
|
# Possible to pass the block
|
26
29
|
#
|
@@ -96,9 +99,9 @@ module Pendragon
|
|
96
99
|
# Prepares the router for route's priority
|
97
100
|
# This method is executed only once in the initial load
|
98
101
|
def prepare!
|
99
|
-
@prepared = true
|
100
102
|
@routes.sort_by!(&:order)
|
101
103
|
@engine = (configuration.enable_compiler? ? Compiler : Recognizer).new(routes)
|
104
|
+
@prepared = true
|
102
105
|
end
|
103
106
|
|
104
107
|
# @return [Boolean] the router is already prepared?
|
@@ -116,7 +119,7 @@ module Pendragon
|
|
116
119
|
# @return [Array]
|
117
120
|
def recognize(request)
|
118
121
|
prepare! unless prepared?
|
119
|
-
@engine.call(request)
|
122
|
+
synchronize { @engine.call(request) }
|
120
123
|
end
|
121
124
|
|
122
125
|
# Recognizes a given path
|
@@ -135,7 +138,7 @@ module Pendragon
|
|
135
138
|
# router.path(:index, :id => 1) #=> "/1"
|
136
139
|
# router.path(:index, :id => 2, :foo => "bar") #=> "/1?foo=bar"
|
137
140
|
def path(name, *args)
|
138
|
-
|
141
|
+
extract_with(name, *args) do |route, params, matcher|
|
139
142
|
matcher.mustermann? ? matcher.expand(params) : route.path
|
140
143
|
end
|
141
144
|
end
|
@@ -148,10 +151,10 @@ module Pendragon
|
|
148
151
|
|
149
152
|
# @!visibility private
|
150
153
|
# @example
|
151
|
-
#
|
154
|
+
# extract_with(:index) do |route, params|
|
152
155
|
# route.matcher.mustermann? ? route.matcher.expand(params) : route.path
|
153
156
|
# end
|
154
|
-
def
|
157
|
+
def extract_with(name, *args)
|
155
158
|
params = args.delete_at(args.last.is_a?(Hash) ? -1 : 0) || {}
|
156
159
|
saved_args = args.dup
|
157
160
|
@routes.each do |route|
|
@@ -171,6 +174,15 @@ module Pendragon
|
|
171
174
|
raise InvalidRouteException
|
172
175
|
end
|
173
176
|
|
174
|
-
private
|
177
|
+
# @!visibility private
|
178
|
+
def synchronize(&block)
|
179
|
+
if configuration.lock?
|
180
|
+
@@mutex.synchronize(&block)
|
181
|
+
else
|
182
|
+
yield
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
private :extract_with, :synchronize
|
175
187
|
end
|
176
188
|
end
|
data/lib/pendragon/version.rb
CHANGED
data/test/padrino_test.rb
CHANGED
@@ -655,7 +655,7 @@ describe "Pendragon::Padrino" do
|
|
655
655
|
assert_equal 'application/javascript;charset=utf-8', response["Content-Type"]
|
656
656
|
get "/a.json"
|
657
657
|
assert_equal "json", body
|
658
|
-
assert_equal 'application/json
|
658
|
+
assert_equal 'application/json', response["Content-Type"]
|
659
659
|
get "/a.foo"
|
660
660
|
assert_equal "foo", body
|
661
661
|
assert_equal 'application/foo;charset=utf-8', response["Content-Type"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pendragon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|