barrister-sinatra 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/barrister-sinatra/version.rb +1 -1
- data/lib/barrister-sinatra.rb +20 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 533384ba51e4ec858ef745450dddced1672c6eb9
|
4
|
+
data.tar.gz: 3f45d6c74203dad7d99e28de55f1dbc843f3f336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49ff9a3b2ce66adf4ba6718021644e2d753b11666bc44bf0a9474823bd8818b39b0bca702c268fb1cb883d750c8cbb07235cec5095572add9357bddd44a21af9
|
7
|
+
data.tar.gz: 58e1bcdae9eeeb446e55723301d83a5766240cad7c1d467bc00371b6d647c7bd1e0798f9004de6cec86030d251817da924c9dc669e8a156ff76a74299d0560aa
|
data/lib/barrister-sinatra.rb
CHANGED
@@ -4,38 +4,34 @@ require 'sinatra/base'
|
|
4
4
|
|
5
5
|
module Barrister
|
6
6
|
|
7
|
-
|
7
|
+
class SinatraContainer
|
8
8
|
|
9
|
-
|
9
|
+
def initialize(json_path, mount_path, handlers, port=4567, host='localhost')
|
10
|
+
@my_app = ::Sinatra.new do
|
11
|
+
set :bind, host
|
12
|
+
set :port, port
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
set :bind, host
|
14
|
-
set :port, port
|
14
|
+
contract = Barrister::contract_from_file json_path
|
15
|
+
server = Barrister::Server.new(contract)
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
handlers.each do |handler_klass|
|
21
|
-
server.add_handler handler_klass.to_s, handler_klass.new
|
22
|
-
end
|
17
|
+
# register each provided handler
|
18
|
+
handlers.each do |handler_klass|
|
19
|
+
server.add_handler handler_klass.to_s, handler_klass.new
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
post mount_path do
|
23
|
+
request.body.rewind
|
24
|
+
resp = server.handle_json(request.body.read)
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
26
|
+
status 200
|
27
|
+
headers 'Content-Type' => 'application/json'
|
28
|
+
resp
|
32
29
|
end
|
33
30
|
end
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
33
|
+
def start
|
34
|
+
@my_app.run!
|
39
35
|
end
|
40
36
|
|
41
37
|
end
|