rack-app 0.15.0 → 0.16.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 +8 -4
- data/VERSION +1 -1
- data/Vagrantfile +13 -0
- data/lib/rack/app.rb +3 -3
- data/lib/rack/app/endpoint.rb +9 -4
- data/lib/rack/app/error_handler.rb +2 -2
- data/lib/rack/app/utils.rb +8 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41c94a79f13a4ee69c813a267eb6a637a955ccbd
|
4
|
+
data.tar.gz: 48abde6b600e6a968b2c6dad2c72b821a7844bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f1f75dbcda528fd377cb77f61eac7f5bf26246ffa9b0e7ba20534eaa5517ee4dce7a3bc0c790285381fbf90319b013c724b11e0f165539b5b0ac0fef9c3cc60
|
7
|
+
data.tar.gz: a187dda8b666fd342430facf104f4aeac8a124a5aa9253c3540d3b1964f48dc60a9b5c07095862a2e71641429d4fe45ad8b83ed5a510cc1eb34734e0fbc372f9
|
data/README.md
CHANGED
@@ -7,9 +7,9 @@
|
|
7
7
|
![Rack::App](http://rack-app-website.herokuapp.com/image/msruby_new.png)
|
8
8
|
|
9
9
|
Your next favourite rack based micro framework that is totally addition free!
|
10
|
-
Have a cup of awesomeness with
|
10
|
+
Have a cup of awesomeness with your performance designed framework!
|
11
11
|
|
12
|
-
The idea behind is simple.
|
12
|
+
The idea behind is simple.
|
13
13
|
Keep the dependencies and everything as little as possible,
|
14
14
|
while able to write pure rack apps,
|
15
15
|
that will do nothing more than what you defined.
|
@@ -17,9 +17,13 @@ that will do nothing more than what you defined.
|
|
17
17
|
If you want see fancy magic, you are in a bad place buddy!
|
18
18
|
This includes that it do not have such core extensions like activesupport that monkey patch the whole world.
|
19
19
|
|
20
|
-
Routing can handle
|
20
|
+
Routing can handle any amount of endpoints that can fit in the memory,
|
21
|
+
so if you that crazy to use more than 10k endpoint,
|
21
22
|
you still dont have to worry about response speed.
|
22
23
|
|
24
|
+
It was inspirited by sinatra, grape, and the pure use form of rack.
|
25
|
+
It's in production, powering Back Ends on Heroku
|
26
|
+
|
23
27
|
## Installation
|
24
28
|
|
25
29
|
Add this line to your application's Gemfile:
|
@@ -76,7 +80,7 @@ class App < Rack::App
|
|
76
80
|
|
77
81
|
desc 'some hello endpoint'
|
78
82
|
get '/hello' do
|
79
|
-
'Hello World!'
|
83
|
+
return 'Hello World!'
|
80
84
|
end
|
81
85
|
|
82
86
|
desc 'some restful endpoint'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.16.0
|
data/Vagrantfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.configure(2) do |config|
|
5
|
+
|
6
|
+
config.vm.box = "ubuntu/trusty64"
|
7
|
+
|
8
|
+
config.vm.provision "shell", inline: "sudo apt-get install -y curl"
|
9
|
+
config.vm.provision "shell", inline: '\curl -sSL https://get.rvm.io | bash'
|
10
|
+
config.vm.provision "shell", inline: 'rvm install 1.8'
|
11
|
+
config.vm.provision "shell", inline: 'rvm install 1.9'
|
12
|
+
|
13
|
+
end
|
data/lib/rack/app.rb
CHANGED
@@ -6,6 +6,9 @@ class Rack::App
|
|
6
6
|
require 'rack/app/version'
|
7
7
|
require 'rack/app/constants'
|
8
8
|
|
9
|
+
require 'rack/app/utils'
|
10
|
+
require 'rack/app/file'
|
11
|
+
|
9
12
|
require 'rack/app/params'
|
10
13
|
require 'rack/app/router'
|
11
14
|
require 'rack/app/endpoint'
|
@@ -14,9 +17,6 @@ class Rack::App
|
|
14
17
|
require 'rack/app/endpoint/not_found'
|
15
18
|
require 'rack/app/request_configurator'
|
16
19
|
|
17
|
-
require 'rack/app/utils'
|
18
|
-
require 'rack/app/file'
|
19
|
-
|
20
20
|
class << self
|
21
21
|
|
22
22
|
def call(request_env)
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -6,15 +6,14 @@ class Rack::App::Endpoint
|
|
6
6
|
@properties = properties
|
7
7
|
|
8
8
|
@error_handler = properties[:error_handler]
|
9
|
-
@logic_block = properties[:user_defined_logic]
|
10
9
|
@serializer = properties[:serializer]
|
11
10
|
@api_class = properties[:app_class]
|
12
11
|
@headers = properties[:default_headers]
|
13
12
|
|
14
13
|
@path_params_matcher = {}
|
14
|
+
@endpoint_method_name = register_method_to_app_class(properties[:user_defined_logic])
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
17
|
def execute(request_env)
|
19
18
|
|
20
19
|
request = Rack::Request.new(request_env)
|
@@ -27,7 +26,7 @@ class Rack::App::Endpoint
|
|
27
26
|
request_handler.response = response
|
28
27
|
request.env['rack.app.path_params_matcher']= @path_params_matcher.dup
|
29
28
|
|
30
|
-
call_return = @error_handler.execute_with_error_handling_for(request_handler
|
29
|
+
call_return = @error_handler.execute_with_error_handling_for(request_handler, @endpoint_method_name)
|
31
30
|
|
32
31
|
return call_return if is_a_rack_response_finish?(call_return)
|
33
32
|
add_response_body_if_missing(call_return, response)
|
@@ -54,9 +53,15 @@ class Rack::App::Endpoint
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def add_default_headers(response)
|
57
|
-
@headers.each do |header,value|
|
56
|
+
@headers.each do |header, value|
|
58
57
|
response.header[header]=value
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
61
|
+
def register_method_to_app_class(proc)
|
62
|
+
method_name = ::Rack::App::Utils.uuid
|
63
|
+
@api_class.__send__(:define_method, method_name, &proc)
|
64
|
+
return method_name
|
65
|
+
end
|
66
|
+
|
62
67
|
end
|
@@ -11,8 +11,8 @@ class Rack::App::ErrorHandler
|
|
11
11
|
nil
|
12
12
|
end
|
13
13
|
|
14
|
-
def execute_with_error_handling_for(instance,
|
15
|
-
instance.
|
14
|
+
def execute_with_error_handling_for(instance, endpoint_method_name)
|
15
|
+
instance.__send__(endpoint_method_name)
|
16
16
|
rescue *[Exception, @handlers.keys].flatten => ex
|
17
17
|
instance.instance_exec(ex, &get_handler(ex))
|
18
18
|
end
|
data/lib/rack/app/utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'securerandom'
|
1
2
|
module Rack::App::Utils
|
2
3
|
extend self
|
3
4
|
|
@@ -29,4 +30,11 @@ module Rack::App::Utils
|
|
29
30
|
|
30
31
|
end
|
31
32
|
|
33
|
+
def uuid
|
34
|
+
ary = SecureRandom.random_bytes(16).unpack("NnnnnN")
|
35
|
+
ary[2] = (ary[2] & 0x0fff) | 0x4000
|
36
|
+
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
37
|
+
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
38
|
+
end
|
39
|
+
|
32
40
|
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: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- README.md
|
86
86
|
- Rakefile
|
87
87
|
- VERSION
|
88
|
+
- Vagrantfile
|
88
89
|
- bin/console
|
89
90
|
- bin/setup
|
90
91
|
- lib/rack/app.rb
|