pendragon 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50f2cc54ef1c804fa05b8de3a47d6bf731e86f8f
4
- data.tar.gz: 90c08c4129ae507b429d35487ff7824a37ad424e
3
+ metadata.gz: 4e7cbea66f8dd29316768cfb0fe023d1406a8b64
4
+ data.tar.gz: 0e01b51a0a24b2ee596bf4f01d228a9885b49269
5
5
  SHA512:
6
- metadata.gz: cf8e88346a526a08c48e63db31f861d4b401754bcaea842e0ac0ce6446e241a0cf51b87d2c61ff6f1dcbf29c4e10d975a078fa31f9413881b578c60845a53a41
7
- data.tar.gz: 070bc4ce928f628ba6f22260e42f05087ee96caccba81c0084a3ccf5fe7491cfa94aebaf7f695a539ef26c9a86944313e0674dd23c9240e255fa23b05bc5e922
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.4)
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.2)
35
- padrino-admin (= 0.12.2)
36
- padrino-cache (= 0.12.2)
37
- padrino-core (= 0.12.2)
38
- padrino-gen (= 0.12.2)
39
- padrino-helpers (= 0.12.2)
40
- padrino-mailer (= 0.12.2)
41
- padrino-support (= 0.12.2)
42
- padrino-admin (0.12.2)
43
- padrino-core (= 0.12.2)
44
- padrino-helpers (= 0.12.2)
45
- padrino-cache (0.12.2)
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.2)
48
- padrino-helpers (= 0.12.2)
49
- padrino-core (0.12.2)
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.2)
52
+ padrino-support (= 0.12.3)
53
53
  rack-protection (>= 1.5.0)
54
54
  sinatra (~> 1.4.2)
55
- thor (~> 0.18.0)
56
- padrino-gen (0.12.2)
55
+ thor (~> 0.18)
56
+ padrino-gen (0.12.3)
57
57
  bundler (~> 1.0)
58
- padrino-core (= 0.12.2)
59
- padrino-helpers (0.12.2)
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.2)
61
+ padrino-support (= 0.12.3)
62
62
  tilt (~> 1.4.1)
63
- padrino-mailer (0.12.2)
63
+ padrino-mailer (0.12.3)
64
64
  mail (~> 2.5.3)
65
- padrino-core (= 0.12.2)
66
- padrino-support (0.12.2)
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.18.1)
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.1)
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
- !!@regexps
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
- # Recognized routes, and returns them
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) || @_parents
202
- parent_params = (Array(@_parents) + Array(parent_params)).uniq
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
- extract_with_name(name, *args) do |route, params, matcher|
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
@@ -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
- extract_with_name(name, *args) do |route, params, matcher|
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
- # extract_with_name(:index) do |route, params|
154
+ # extract_with(:index) do |route, params|
152
155
  # route.matcher.mustermann? ? route.matcher.expand(params) : route.path
153
156
  # end
154
- def extract_with_name(name, *args)
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 :extract_with_name
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
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Pendragon
3
- VERSION = '0.5.1'
3
+ VERSION = '0.6.0'
4
4
  end
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;charset=utf-8', response["Content-Type"]
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.5.1
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-07-24 00:00:00.000000000 Z
11
+ date: 2014-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack