rack-app 7.5.1 → 7.5.2

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: 0fa1cbbfa3a7debe947b55c0f876563c3d41bc29
4
- data.tar.gz: 7275baae82226050a885bfa29dafb205e41cedab
3
+ metadata.gz: 685044ceae379bb1f514e908eec4f1cf747b7410
4
+ data.tar.gz: 238ae60171c5a954598a548b6daeab3aa37a2595
5
5
  SHA512:
6
- metadata.gz: 495a0e592d611f7ea125c85468efd76a5d254ff4d387e4115da8bf16a135e8779419d182b9eea9b92ab91bbeb7f89609edc2bcce4d9d8fe119e76b22c8e51da4
7
- data.tar.gz: 043431aa915f8d5eaaabd78f2cb6f62cd95db9af21e5a14ad4356ad27ea293e86761e1b9d81e6951f46962f8fd97cc0103c87640feee8133470929e28f63bce8
6
+ metadata.gz: f03f8c6bd826cd76337141ae81894555b47a4c327478566df7481643256e11fc1922b9d410476375040371099a0e24881e3e4ed43faf9e35d29b0479fe0cad07
7
+ data.tar.gz: 1ecea638458f5af0e04659d774680ac7bc2e68def972046332082041198a3dcced104bf0fc91dd789c924ae5fb85743f380c9d23ce3f9270246af27342e10a85
data/README.md CHANGED
@@ -94,6 +94,12 @@ Yes, in fact it's already powering heroku hosted micro-services.
94
94
  * note that this is not only memory friendly way pure rack solution, but also 2x faster than the usually solution which includes buffering in memory
95
95
  * params validation with ease
96
96
 
97
+ ## Under the hood
98
+
99
+ rack-app's router relies on a tree structure which makes heavy use of *common prefixes*,
100
+ it is basically a *compact* [*prefix tree*](https://en.wikipedia.org/wiki/Trie) (or just [*Radix tree*](https://en.wikipedia.org/wiki/Radix_tree)).
101
+ Nodes with a common prefix also share a common parent.
102
+
97
103
  ## Contributors
98
104
 
99
105
  * **[Daniel Nagy](https://github.com/thilonel)**
@@ -112,12 +118,14 @@ Yes, in fact it's already powering heroku hosted micro-services.
112
118
 
113
119
  * [wrote an awesome article](https://www.sitepoint.com/rack-app-a-performant-and-pragmatic-web-microframework/) about the project
114
120
 
121
+ * **[TheSmartnik](https://github.com/TheSmartnik)**
122
+
123
+ * Clarify examples in the documentation
124
+
115
125
  ## [Contributing](CONTRIBUTING.md)
116
126
 
117
127
  ## Usage
118
128
 
119
- config.ru
120
-
121
129
  #### basic
122
130
 
123
131
  ```ruby
@@ -143,8 +151,6 @@ require 'rack/app'
143
151
 
144
152
  class App < Rack::App
145
153
 
146
- apply_extensions :front_end
147
-
148
154
  mount SomeAppClass
149
155
 
150
156
  headers 'Access-Control-Allow-Origin' => '*',
@@ -158,11 +164,12 @@ class App < Rack::App
158
164
  validate_params do
159
165
  required 'words', :class => Array, :of => String, :desc => 'some word', :example => ['pug']
160
166
  optional 'word', :class => String, :desc => 'one word', :example => 'pug'
167
+ optional 'boolean', :class => :boolean, :desc => 'boolean value', :example => true
161
168
  end
162
169
  get '/hello' do
163
- puts(validate_params['words'])
170
+ puts(params['words'])
164
171
 
165
- return 'Hello World!'
172
+ 'Hello World!'
166
173
  end
167
174
 
168
175
  namespace '/users' do
@@ -206,6 +213,40 @@ Rack::Response as response method.
206
213
 
207
214
  By default if you dont write anything to the response 'body' the endpoint block logic return will be used
208
215
 
216
+ ### Frontend Example
217
+
218
+ if you don't mind extend your dependency list, than you can use the front_end extension for creating template based web applications.
219
+
220
+ ```ruby
221
+ require 'rack/app'
222
+ require 'rack/app/front_end' # You need to add `gem 'rack-app-front_end'` to your Gemfile
223
+
224
+ class App < Rack::App
225
+
226
+ apply_extensions :front_end
227
+
228
+ helpers do
229
+
230
+ def method_that_can_be_used_in_template
231
+ 'hello world!'
232
+ end
233
+
234
+ end
235
+
236
+ # use ./app/layout.html.erb as layout, this is optionable
237
+ layout 'layout.html.erb'
238
+
239
+ # at '/' the endpoint will serve (render)
240
+ # the ./app/index.html content as response body and wrap around with layout if layout is given
241
+ get '/' do
242
+ render 'index.html'
243
+ end
244
+
245
+ end
246
+ ```
247
+
248
+ this example expects an "app" folder next to the "app.rb" file that included templates being used such as layout.html.erb and index.html.
249
+
209
250
  ## Testing
210
251
 
211
252
  for testing use rack/test or the bundled testing module for writing unit test for your rack application
@@ -223,7 +264,7 @@ describe App do
223
264
 
224
265
  describe '/hello' do
225
266
  # example for params and headers and payload use
226
- subject{ get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}, payload: 'some string') }
267
+ subject { get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}, payload: 'some string') }
227
268
 
228
269
  it { expect(subject.status).to eq 200 }
229
270
 
@@ -232,7 +273,7 @@ describe App do
232
273
 
233
274
  describe '/users/:user_id' do
234
275
  # restful endpoint example
235
- subject{ get(url: '/users/1234') }
276
+ subject { get(url: '/users/1234') }
236
277
 
237
278
  it { expect(subject.body).to eq 'hello 1234!'}
238
279
 
@@ -242,7 +283,7 @@ describe App do
242
283
 
243
284
  describe '/make_error' do
244
285
  # error handled example
245
- subject{ get(url: '/make_error') }
286
+ subject { get(url: '/make_error') }
246
287
 
247
288
  it { expect(subject.body).to eq '{:error=>"error block rescued"}' }
248
289
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.5.1
1
+ 7.5.2
@@ -1,7 +1,7 @@
1
1
  class Rack::App::Middlewares::SetPathParams
2
2
 
3
- def initialize(app, params_lookup_hash)
4
- @params_lookup_hash = params_lookup_hash
3
+ def initialize(app, build_env)
4
+ @build_env = build_env
5
5
  @app = app
6
6
  end
7
7
 
@@ -16,19 +16,21 @@ class Rack::App::Middlewares::SetPathParams
16
16
  protected
17
17
 
18
18
  def populate_path_params(env)
19
- @params_lookup_hash.each do |index, key|
19
+ @build_env.params.each do |index, key|
20
20
  env[E::PATH_SEGMENTS_PARAMS][key] = env[E::SPLITTED_PATH_INFO][index]
21
21
  end
22
22
  end
23
23
 
24
24
  def correct_last_value_from_extensions(env)
25
+ return if @build_env.endpoint.config.serializer.extnames.empty?
25
26
  last_index = env[E::SPLITTED_PATH_INFO].length - 1
26
- return if @params_lookup_hash[last_index].nil?
27
- extless(env[E::PATH_SEGMENTS_PARAMS][@params_lookup_hash[last_index]])
27
+ return if @build_env.params[last_index].nil?
28
+ extless(env[E::PATH_SEGMENTS_PARAMS][@build_env.params[last_index]])
28
29
  end
29
30
 
30
31
  def extless(value)
31
32
  extname = File.extname(value)
33
+ return unless @build_env.endpoint.config.serializer.extnames.include?(extname)
32
34
  value.slice!(/#{Regexp.escape(extname)}$/) unless extname.empty?
33
35
  end
34
36
 
@@ -48,5 +48,4 @@ class Rack::App::Router::Tree::Leaf < ::Hash
48
48
  self[path_part] ||= Rack::App::Router::Tree::Vein.new
49
49
  end
50
50
 
51
-
52
51
  end
@@ -21,12 +21,12 @@ class Rack::App::Router::Tree::Vein < ::Hash
21
21
 
22
22
  def create_app(env)
23
23
  app = env.endpoint.to_app
24
- env.params.empty? ? app : wrap(app, env.params)
24
+ env.params.empty? ? app : wrap(app, env)
25
25
  end
26
26
 
27
- def wrap(app, params)
27
+ def wrap(app, env)
28
28
  builder = Rack::Builder.new
29
- builder.use(Rack::App::Middlewares::SetPathParams, params)
29
+ builder.use(Rack::App::Middlewares::SetPathParams, env)
30
30
  builder.run(app)
31
31
  builder.to_app
32
32
  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: 7.5.1
4
+ version: 7.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-26 00:00:00.000000000 Z
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  requirements: []
228
228
  rubyforge_project:
229
- rubygems_version: 2.6.14
229
+ rubygems_version: 2.6.8
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: Your next favourite, performance designed micro framework!