rack-app 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -35
- data/VERSION +1 -1
- data/lib/rack/app.rb +14 -12
- data/lib/rack/app/constants.rb +4 -0
- data/lib/rack/app/request_configurator.rb +10 -0
- metadata +4 -3
- data/Gemfile.lock +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5ede34a09c9d0097e937f1e1eed2b2a407b58a8
|
4
|
+
data.tar.gz: 0e34dd9cbdf1727858035651595f19ef3e202447
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d3a9d617fa9b6517f47341cd7c37b77ae24f5fd057c17bbd3203f59200b1b519582824146bdb953698d6525b4c310ec0d9eb20496fe92efb38f91d2e478ae94
|
7
|
+
data.tar.gz: d2b13fe4887da9e1f041cc9cf4de3c1a5a9acaf9f0c383ef07afd7a86fe41913a0c2a1db72b0e3d32735d0c69691b59a721128a49cf6449ac08d023c8541e699
|
data/README.md
CHANGED
@@ -37,42 +37,24 @@ config.ru
|
|
37
37
|
|
38
38
|
require 'rack/app'
|
39
39
|
|
40
|
-
require_relative 'lib/bootstrap'
|
41
|
-
|
42
40
|
class YourAwesomeApp < Rack::App
|
43
41
|
|
44
|
-
mount AwesomeController
|
45
|
-
|
46
42
|
get '/hello' do
|
47
43
|
'Hello World!'
|
48
44
|
end
|
49
45
|
|
50
|
-
get '/nope' do
|
51
|
-
request.env
|
52
|
-
response.write 'some response body'
|
53
|
-
end
|
54
|
-
|
55
|
-
post '/lol_post_fail' do
|
56
|
-
status 500
|
57
|
-
'LOL'
|
58
|
-
end
|
59
|
-
|
60
46
|
get '/users/:user_id' do
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
post '/some/endpoint/for/the/rabbit/:queue_name' do
|
65
|
-
mq_request # helper are the class instance method
|
47
|
+
get_user_id
|
66
48
|
end
|
67
49
|
|
68
|
-
def
|
69
|
-
|
70
|
-
BUNNY_CONN_CHANNEL.default_exchange.publish(request.body.read, :routing_key => q.name)
|
50
|
+
def get_user_id
|
51
|
+
params['user_id']
|
71
52
|
end
|
72
53
|
|
73
54
|
end
|
74
55
|
|
75
56
|
run YourAwesomeApp
|
57
|
+
|
76
58
|
```
|
77
59
|
|
78
60
|
you can access Rack::Request with the request method and
|
@@ -86,7 +68,7 @@ use bundled in testing module for writing unit test for your rack application
|
|
86
68
|
|
87
69
|
```ruby
|
88
70
|
|
89
|
-
|
71
|
+
require 'spec_helper'
|
90
72
|
require 'rack/app/test'
|
91
73
|
|
92
74
|
describe MyRackApp do
|
@@ -119,37 +101,33 @@ end
|
|
119
101
|
|
120
102
|
## [Benchmarking](https://github.com/adamluzsi/rack-app.rb-benchmark)
|
121
103
|
|
122
|
-
*
|
104
|
+
* Dumb duration with zero if or routing: 5.0e-06 s - 6.0e-06 s
|
123
105
|
* no routing
|
124
106
|
* return only a static array with static values
|
125
|
-
* Rack::App duration with routing lookup: 7.0e-05 s
|
107
|
+
* Rack::App duration with routing lookup: 6.3e-05 s - 7.0e-05 s
|
126
108
|
* with routing
|
127
109
|
* with value parsing and reponse object building
|
128
|
-
* Grape::API duration with routing lookup: 0.180764 s
|
110
|
+
* Grape::API duration with routing lookup: 0.028236 s - 0.180764 s
|
129
111
|
* with routing
|
130
112
|
* with value parsing and reponse object building
|
131
113
|
|
132
114
|
This was measured with multiple endpoints like that would be in real life example.
|
133
115
|
i feared do this for Rails that is usually slower than Grape :S
|
134
116
|
|
135
|
-
## TODO
|
136
|
-
|
137
|
-
* benchmark for Rails::API, Grape::API and etc to prove awesomeness in term of speed
|
138
|
-
* more verbose readme
|
139
|
-
* drink less coffee
|
140
|
-
|
141
117
|
## Roadmap
|
142
118
|
|
143
|
-
### 0.
|
119
|
+
### 0.7.0
|
144
120
|
|
145
121
|
* serializer block/method for class shared serialization logic
|
122
|
+
* Mount method should able to take namespace option
|
123
|
+
* Create erb Parser Gem for View/FileServer to support to .erb files
|
146
124
|
|
147
|
-
### 0.
|
125
|
+
### 0.8.0
|
148
126
|
|
149
127
|
* content_type syntax sugar on class level
|
150
128
|
* response_headers syntax sugar for request processing
|
151
129
|
|
152
|
-
### 0.
|
130
|
+
### 0.9.0
|
153
131
|
|
154
132
|
* custom error_handler block for api, where Exception class types can be defined to process
|
155
133
|
* NULL Object pattern for error_handler_fetcher
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/rack/app.rb
CHANGED
@@ -4,17 +4,22 @@ require 'rack/response'
|
|
4
4
|
class Rack::App
|
5
5
|
|
6
6
|
require 'rack/app/version'
|
7
|
+
require 'rack/app/constants'
|
7
8
|
|
8
9
|
require 'rack/app/params'
|
9
10
|
require 'rack/app/utils'
|
10
11
|
require 'rack/app/router'
|
11
12
|
require 'rack/app/endpoint'
|
12
13
|
require 'rack/app/endpoint/not_found'
|
14
|
+
require 'rack/app/request_configurator'
|
13
15
|
|
14
16
|
class << self
|
15
17
|
|
16
18
|
def call(request_env)
|
17
|
-
|
19
|
+
Rack::App::RequestConfigurator.configure(request_env)
|
20
|
+
endpoint = router.fetch_endpoint(
|
21
|
+
request_env['REQUEST_METHOD'],
|
22
|
+
request_env[Rack::App::Constants::NORMALIZED_REQUEST_PATH])
|
18
23
|
endpoint.execute(request_env)
|
19
24
|
end
|
20
25
|
|
@@ -50,6 +55,13 @@ class Rack::App
|
|
50
55
|
add_route('PATCH', path, &block)
|
51
56
|
end
|
52
57
|
|
58
|
+
def root(endpoint_path)
|
59
|
+
get '/' do
|
60
|
+
endpoint = self.class.router.fetch_endpoint('GET', Rack::App::Utils.normalize_path(endpoint_path))
|
61
|
+
endpoint.execute(request.env)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
53
65
|
def router
|
54
66
|
@router ||= Rack::App::Router.new
|
55
67
|
end
|
@@ -62,10 +74,7 @@ class Rack::App
|
|
62
74
|
description: @last_description
|
63
75
|
}
|
64
76
|
|
65
|
-
endpoint = Rack::App::Endpoint.new(
|
66
|
-
self, endpoint_properties, &block
|
67
|
-
)
|
68
|
-
|
77
|
+
endpoint = Rack::App::Endpoint.new(self, endpoint_properties, &block)
|
69
78
|
router.add_endpoint(request_method, request_path, endpoint)
|
70
79
|
|
71
80
|
@last_description = nil
|
@@ -73,7 +82,6 @@ class Rack::App
|
|
73
82
|
|
74
83
|
end
|
75
84
|
|
76
|
-
|
77
85
|
def mount(api_class)
|
78
86
|
|
79
87
|
unless api_class.is_a?(Class) and api_class <= Rack::App
|
@@ -91,12 +99,6 @@ class Rack::App
|
|
91
99
|
@__params__ ||= Rack::App::Params.new(request.env).to_hash
|
92
100
|
end
|
93
101
|
|
94
|
-
def status(new_status=nil)
|
95
|
-
response.status= new_status.to_i unless new_status.nil?
|
96
|
-
|
97
|
-
response.status
|
98
|
-
end
|
99
|
-
|
100
102
|
attr_writer :request, :response
|
101
103
|
|
102
104
|
def request
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,16 +78,17 @@ files:
|
|
78
78
|
- ".rspec"
|
79
79
|
- CODE_OF_CONDUCT.md
|
80
80
|
- Gemfile
|
81
|
-
- Gemfile.lock
|
82
81
|
- LICENSE
|
83
82
|
- README.md
|
84
83
|
- Rakefile
|
85
84
|
- VERSION
|
86
85
|
- bin/setup
|
87
86
|
- lib/rack/app.rb
|
87
|
+
- lib/rack/app/constants.rb
|
88
88
|
- lib/rack/app/endpoint.rb
|
89
89
|
- lib/rack/app/endpoint/not_found.rb
|
90
90
|
- lib/rack/app/params.rb
|
91
|
+
- lib/rack/app/request_configurator.rb
|
91
92
|
- lib/rack/app/router.rb
|
92
93
|
- lib/rack/app/router/dynamic.rb
|
93
94
|
- lib/rack/app/router/static.rb
|
data/Gemfile.lock
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
rack-app (0.5.0)
|
5
|
-
rack
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
diff-lcs (1.2.5)
|
11
|
-
rack (1.6.4)
|
12
|
-
rake (10.4.2)
|
13
|
-
rspec (3.3.0)
|
14
|
-
rspec-core (~> 3.3.0)
|
15
|
-
rspec-expectations (~> 3.3.0)
|
16
|
-
rspec-mocks (~> 3.3.0)
|
17
|
-
rspec-core (3.3.2)
|
18
|
-
rspec-support (~> 3.3.0)
|
19
|
-
rspec-expectations (3.3.1)
|
20
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
-
rspec-support (~> 3.3.0)
|
22
|
-
rspec-mocks (3.3.2)
|
23
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.3.0)
|
25
|
-
rspec-support (3.3.0)
|
26
|
-
|
27
|
-
PLATFORMS
|
28
|
-
ruby
|
29
|
-
|
30
|
-
DEPENDENCIES
|
31
|
-
bundler (~> 1.10)
|
32
|
-
rack-app!
|
33
|
-
rake (~> 10.0)
|
34
|
-
rspec
|
35
|
-
|
36
|
-
BUNDLED WITH
|
37
|
-
1.10.6
|