rack-app 0.9.1 → 0.9.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 +4 -4
- data/README.md +7 -6
- data/VERSION +1 -1
- data/lib/rack/app.rb +9 -2
- data/lib/rack/app/endpoint.rb +11 -4
- data/lib/rack/app/endpoint/not_found.rb +15 -6
- data/lib/rack/app/test.rb +1 -1
- data/rack-app.gemspec +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11562e09e4e7087bbaefaeb911d0ce5a87cf80e6
|
4
|
+
data.tar.gz: deefda74befc47f77bc3c7c6f65b0420772a936a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 290f0f4386397f899f4101268c12d0ccc1a7ab06d6ecb224f141915994544bfb77021b34f52eea87b109e0b67a8f7910a25c17ad15b8ca3eea6a3c60f714d6be
|
7
|
+
data.tar.gz: db9c38482271907d84fd88db8de910b228f77a2c7f7be0ee08c20584b86c6f59c8a0b74496eac020ba9feb39b89199b9f04a9f0f8c52fc2d51c4dd38a7c6ba52
|
data/README.md
CHANGED
@@ -47,12 +47,13 @@ class YourAwesomeApp < Rack::App
|
|
47
47
|
'Hello World!'
|
48
48
|
end
|
49
49
|
|
50
|
-
get '/users/:user_id' do
|
51
|
-
|
50
|
+
get '/users/:user_id' do
|
51
|
+
params['user_id'] #=> restful parameter :user_id
|
52
|
+
say #=> "hello world!"
|
52
53
|
end
|
53
54
|
|
54
|
-
def
|
55
|
-
|
55
|
+
def say
|
56
|
+
'hello world!'
|
56
57
|
end
|
57
58
|
|
58
59
|
end
|
@@ -68,7 +69,7 @@ By default if you dont write anything to the response 'body' the endpoint block
|
|
68
69
|
|
69
70
|
## Testing
|
70
71
|
|
71
|
-
use bundled
|
72
|
+
for testing use rack/test or the bundled testing module for writing unit test for your rack application
|
72
73
|
|
73
74
|
```ruby
|
74
75
|
|
@@ -83,7 +84,7 @@ describe MyRackApp do
|
|
83
84
|
|
84
85
|
describe '#something' do
|
85
86
|
|
86
|
-
subject{ get('/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}) }
|
87
|
+
subject{ get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}) }
|
87
88
|
|
88
89
|
it { expect(subject.body).to eq ['world']}
|
89
90
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
data/lib/rack/app.rb
CHANGED
@@ -77,12 +77,15 @@ class Rack::App
|
|
77
77
|
def add_route(request_method, request_path, &block)
|
78
78
|
|
79
79
|
endpoint_properties = {
|
80
|
+
:user_defined_logic => block,
|
80
81
|
:request_method => request_method,
|
81
82
|
:request_path => request_path,
|
82
|
-
:description => @last_description
|
83
|
+
:description => @last_description,
|
84
|
+
:serializer => @serializer,
|
85
|
+
:app_class => self
|
83
86
|
}
|
84
87
|
|
85
|
-
endpoint = Rack::App::Endpoint.new(
|
88
|
+
endpoint = Rack::App::Endpoint.new(endpoint_properties)
|
86
89
|
router.add_endpoint(request_method, request_path, endpoint)
|
87
90
|
|
88
91
|
@last_description = nil
|
@@ -101,6 +104,10 @@ class Rack::App
|
|
101
104
|
return nil
|
102
105
|
end
|
103
106
|
|
107
|
+
def serializer(&code)
|
108
|
+
@serializer = code
|
109
|
+
end
|
110
|
+
|
104
111
|
end
|
105
112
|
|
106
113
|
def params
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -2,13 +2,16 @@ class Rack::App::Endpoint
|
|
2
2
|
|
3
3
|
attr_reader :properties
|
4
4
|
|
5
|
-
def initialize(
|
5
|
+
def initialize(properties)
|
6
6
|
@properties = properties
|
7
|
-
@logic_block =
|
8
|
-
@
|
7
|
+
@logic_block = properties[:user_defined_logic]
|
8
|
+
@serializer = properties[:serializer] || default_serializer
|
9
|
+
@api_class = properties[:app_class]
|
10
|
+
|
9
11
|
@path_params_matcher = {}
|
10
12
|
end
|
11
13
|
|
14
|
+
|
12
15
|
def execute(request_env)
|
13
16
|
|
14
17
|
request = Rack::Request.new(request_env)
|
@@ -36,7 +39,7 @@ class Rack::App::Endpoint
|
|
36
39
|
protected
|
37
40
|
|
38
41
|
def add_response_body_if_missing(call_return, response)
|
39
|
-
response.write(call_return
|
42
|
+
response.write(String(@serializer.call(call_return))) if response.body.empty?
|
40
43
|
end
|
41
44
|
|
42
45
|
def is_a_rack_response_finish?(call_return)
|
@@ -46,4 +49,8 @@ class Rack::App::Endpoint
|
|
46
49
|
call_return[1].is_a?(Hash)
|
47
50
|
end
|
48
51
|
|
52
|
+
def default_serializer
|
53
|
+
lambda { |o| o.to_s }
|
54
|
+
end
|
55
|
+
|
49
56
|
end
|
@@ -1,6 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
app_class = Class.new(Rack::App)
|
2
|
+
not_found_properties = {
|
3
|
+
:user_defined_logic => lambda {
|
4
|
+
response.status= 404
|
5
|
+
response.write '404 Not Found'
|
6
|
+
response.finish
|
7
|
+
},
|
8
|
+
:request_method => 'GET',
|
9
|
+
:request_path => '\404',
|
10
|
+
:description => 'page not found',
|
11
|
+
:serializer => lambda { |o| String(o) },
|
12
|
+
:app_class => app_class
|
13
|
+
}
|
14
|
+
|
15
|
+
Rack::App::Endpoint::NOT_FOUND = Rack::App::Endpoint.new(not_found_properties)
|
data/lib/rack/app/test.rb
CHANGED
@@ -21,7 +21,7 @@ module Rack::App::Test
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
[:get, :post, :put, :delete, :options].each do |request_method|
|
24
|
+
[:get, :post, :put, :delete, :options, :patch].each do |request_method|
|
25
25
|
define_method(request_method) do |properties|
|
26
26
|
properties ||= Hash.new
|
27
27
|
url = properties.delete(:url)
|
data/rack-app.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
7
7
|
|
8
8
|
spec.name = "rack-app"
|
9
9
|
spec.version = File.read(File.join(File.dirname(__FILE__), 'VERSION')).strip
|
10
|
-
spec.authors = ["Adam Luzsi"]
|
11
|
-
spec.email = ["adamluzsi@gmail.com"]
|
10
|
+
spec.authors = ["Adam Luzsi","Daniel Nagy"]
|
11
|
+
spec.email = ["adamluzsi@gmail.com","naitodai@gmail.com"]
|
12
12
|
|
13
13
|
spec.summary = %q{Your next favourite, performance designed micro framework!}
|
14
14
|
spec.description = %q{Your next favourite rack based micro framework that is totally addition free! Have a cup of awesomeness with your to performance designed framework!}
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
|
+
- Daniel Nagy
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2016-01-09 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -70,6 +71,7 @@ description: Your next favourite rack based micro framework that is totally addi
|
|
70
71
|
free! Have a cup of awesomeness with your to performance designed framework!
|
71
72
|
email:
|
72
73
|
- adamluzsi@gmail.com
|
74
|
+
- naitodai@gmail.com
|
73
75
|
executables: []
|
74
76
|
extensions: []
|
75
77
|
extra_rdoc_files: []
|