rack-app 0.5.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a061f4202e995da2a1325944ec7586052d30a603
4
- data.tar.gz: 193cb7950307a6161f8095b9f90073024241daff
3
+ metadata.gz: d5ede34a09c9d0097e937f1e1eed2b2a407b58a8
4
+ data.tar.gz: 0e34dd9cbdf1727858035651595f19ef3e202447
5
5
  SHA512:
6
- metadata.gz: 5bccaeb4dcd6599eb14003434dc54dda1cb8d31f93968c7e5fccf1420e7cbdf427d3d6728f897a9557868fa9fb8681c1ebeac8189f5e6a8261d4b202d126f38f
7
- data.tar.gz: 734d959b060a38c58ecea6f7214d33bf3396c7ba71704c4cb6d90c893086a7cdbb162e41945ea626f9c6c693cad24fff8e5126c1016515056f299c3387c90ecb
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
- params['user_id']
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 mq_request
69
- q = BUNNY_CONN_CHANNEL.queue(params['queue_name'])
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
- require_relative '../../spec_helper'
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
- * Dump duration with zero if or routing: 6.0e-06 s
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.6.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.7.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.8.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.5.0
1
+ 0.6.0
@@ -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
- endpoint = router.fetch_endpoint(request_env['REQUEST_METHOD'],request_env['REQUEST_PATH'])
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
@@ -0,0 +1,4 @@
1
+ module Rack::App::Constants
2
+ NORMALIZED_REQUEST_PATH = 'NORMALIZED_REQUEST_PATH'
3
+
4
+ end
@@ -0,0 +1,10 @@
1
+ module Rack::App::RequestConfigurator
2
+
3
+ extend self
4
+
5
+ def configure(request_env)
6
+ request_env[Rack::App::Constants::NORMALIZED_REQUEST_PATH]= Rack::App::Utils.normalize_path(request_env['REQUEST_PATH'])
7
+ request_env
8
+ end
9
+
10
+ end
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.5.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-03 00:00:00.000000000 Z
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
@@ -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