rack-app 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/rack/app.rb +19 -11
  4. metadata +2 -3
  5. data/spike/routing_time.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcf583155bb66f40c777bc3dba6b0dc754ce0926
4
- data.tar.gz: 7b6f52fc9f2699a63c7fade728e35192f923acf4
3
+ metadata.gz: 1f0212581c0302e96e3c57653717c120176b4ba5
4
+ data.tar.gz: f9b8d8261cd14ebe2ca18a16d5911005a87f7fd4
5
5
  SHA512:
6
- metadata.gz: 4d9fbba41397157e2ac4baf427ac52fbd4b8c73ccdea7fc83ce5e00452030694a7f12568c1e95457eb1ac961dde2acdbdea910cb9853a4c439620ca8e3cd4c89
7
- data.tar.gz: 9d8438688db056c7efef3f1e7b56f4d7b662e2baabde3dd99df70ba0f8335415e6028c7f8b976ddcceb0c9db5bd9cce384ee145a8ed56253c464b5e2cb820a15
6
+ metadata.gz: 82ccad0eb43f24cfa18bf39989d91e86fca8e80e6706c76858d4163a5eb7a3274256752cd50910a83d71c8029f2e9f47d0eedb28824a011951b7f726ac8c9a65
7
+ data.tar.gz: 16670b0e9bb15820d5d82d3fc62534f839aeb69aef532b489226786f8b72016ea0a23473af90d012c5deda569ac42d8e38af6b5d551bc6a743f29d37e0b046da
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -120,16 +120,17 @@ class Rack::App
120
120
  add_route('PATCH', path, &block)
121
121
  end
122
122
 
123
- def root(endpoint_path)
124
- normalized_path = Rack::App::Utils.normalize_path(endpoint_path)
125
-
126
- options '/' do
127
- endpoint = self.class.router.fetch_endpoint('OPTIONS', normalized_path)
128
- endpoint.get_response_body(request, response)
123
+ def alias_endpoint(new_request_path, original_request_path)
124
+ router.endpoints.select { |ep| ep[:request_path] == original_request_path }.each do |endpoint|
125
+ router.register_endpoint!(endpoint[:request_method], new_request_path, endpoint[:description], endpoint[:endpoint])
129
126
  end
130
- get '/' do
131
- endpoint = self.class.router.fetch_endpoint('GET', normalized_path)
132
- endpoint.get_response_body(request, response)
127
+ end
128
+
129
+ def root(endpoint_path)
130
+ %W[GET POST PUT DELETE OPTIONS PATCH HEAD].each do |request_method|
131
+ endpoint = router.fetch_endpoint(request_method, endpoint_path)
132
+ next if endpoint == Rack::App::Endpoint::NOT_FOUND
133
+ router.register_endpoint!(request_method, '/', 'Root endpoint', endpoint)
133
134
  end
134
135
  end
135
136
 
@@ -185,12 +186,12 @@ class Rack::App
185
186
 
186
187
  end
187
188
 
189
+ attr_writer :request, :response
190
+
188
191
  def params
189
192
  @__params__ ||= Rack::App::Params.new(request.env).to_hash
190
193
  end
191
194
 
192
- attr_writer :request, :response
193
-
194
195
  def request
195
196
  @request || raise("request object is not set for #{self.class}")
196
197
  end
@@ -213,4 +214,11 @@ class Rack::App
213
214
  }.call
214
215
  end
215
216
 
217
+ def redirect_to(url)
218
+ url = "#{url}?#{request.env['QUERY_STRING']}" unless request.env['QUERY_STRING'].empty?
219
+ response.status = 301
220
+ response.headers.merge!({'Location' => url})
221
+ 'See Ya!'
222
+ end
223
+
216
224
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-02-25 00:00:00.000000000 Z
12
+ date: 2016-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -108,7 +108,6 @@ files:
108
108
  - lib/rack/app/utils.rb
109
109
  - lib/rack/app/version.rb
110
110
  - rack-app.gemspec
111
- - spike/routing_time.rb
112
111
  homepage: https://github.com/rack-app
113
112
  licenses:
114
113
  - Apache License 2.0
@@ -1,40 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'rack/app'
3
- require 'securerandom'
4
-
5
- static_router = Rack::App::Router::Static.new
6
- dynamic_router = Rack::App::Router::Dynamic.new
7
-
8
- classic_router = []
9
-
10
- endpoint_paths = []
11
- 10000.times do
12
- endpoint_paths << ('/' + 7.times.map { SecureRandom.uuid }.join('/'))
13
-
14
- static_router.add_endpoint('GET', endpoint_paths.last, -> {})
15
- static_router.add_endpoint('GET', endpoint_paths.last, -> {})
16
- classic_router << ['GET',endpoint_paths.last,->{}]
17
-
18
- end
19
-
20
- start_time = Time.now
21
- endpoint_paths.each do |request_path|
22
- static_router.fetch_endpoint('GET',request_path)
23
- end
24
- finish_time_of_static = Time.now - start_time
25
-
26
- start_time = Time.now
27
- endpoint_paths.each do |request_path|
28
- dynamic_router.fetch_endpoint('GET',request_path)
29
- end
30
- finish_time_of_dynamic = Time.now - start_time
31
-
32
- start_time = Time.now
33
- endpoint_paths.each do |request_path|
34
- classic_router.find{|ary| ary[0] == 'GET' and ary[1] == request_path }
35
- end
36
- finish_time_of_classic = Time.now - start_time
37
-
38
- puts "time taken by static: #{finish_time_of_static}",
39
- "time taken by dynamic: #{finish_time_of_dynamic}",
40
- "time taken by classic(mock): #{finish_time_of_classic}"