barrister-sinatra 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -4
- data/lib/barrister-sinatra.rb +16 -6
- data/lib/barrister-sinatra/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1c0cfd8b70cf885a4149b72195397cbb74fc364
|
4
|
+
data.tar.gz: 5734c4b907037de4b38dc52c5d8b8060ca505d91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82c7c8612c9394bda76ac9e55069985d99cc767e0b5c8a5530d5a5c93ee8409f1e3c29fe6c8e827f9334ae565c304014ff14dd99df319d1661f60161dc72506a
|
7
|
+
data.tar.gz: ff68d0650c676669081294bc91dceffaf9dd5d448d2da05a574cc9194cb138e7796d16ec8f5c49769f9420080e828d6636d0f8e9cd833d18c624d6f20c98b262
|
data/README.md
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
|
3
3
|
A Sinatra container for services using Barrister RPC framework
|
4
4
|
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Instantiating a Sinatra container is easy:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
|
11
|
+
json_path = './user_service.json'
|
12
|
+
mount_path = '/user_service'
|
13
|
+
handlers = [UserService]
|
14
|
+
|
15
|
+
container = Barrister::SinatraContainer.new json_path, mount_path, handlers
|
16
|
+
container.start
|
17
|
+
|
18
|
+
```
|
19
|
+
|
20
|
+
Calling the 'start' method of an instantiated SinatraContainer will start the
|
21
|
+
underlying HTTP server and Sinatra application.
|
22
|
+
|
5
23
|
## Installation
|
6
24
|
|
7
25
|
Add this line to your application's Gemfile:
|
@@ -16,10 +34,6 @@ Or install it yourself as:
|
|
16
34
|
|
17
35
|
$ gem install barrister-sinatra
|
18
36
|
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
37
|
## Contributing
|
24
38
|
|
25
39
|
1. Fork it ( http://github.com/<my-github-username>/barrister-sinatra/fork )
|
data/lib/barrister-sinatra.rb
CHANGED
@@ -6,20 +6,30 @@ module Barrister
|
|
6
6
|
|
7
7
|
class SinatraContainer
|
8
8
|
|
9
|
-
def initialize(json_path,
|
9
|
+
def initialize(json_path, handlers, options={})
|
10
|
+
options = {
|
11
|
+
mount_path: '/' + json_path.split('/')[-1].split('.')[0],
|
12
|
+
port: 3001,
|
13
|
+
host: 'localhost'
|
14
|
+
}.merge(options)
|
15
|
+
|
10
16
|
@my_app = ::Sinatra.new do
|
11
|
-
set :bind, host
|
12
|
-
set :port, port
|
17
|
+
set :bind, options[:host]
|
18
|
+
set :port, options[:port]
|
13
19
|
|
14
20
|
contract = Barrister::contract_from_file json_path
|
15
21
|
server = Barrister::Server.new(contract)
|
16
22
|
|
23
|
+
# in case we are passed a single handler
|
24
|
+
handlers = handlers.kind_of?(Array) ? handlers : [handlers]
|
25
|
+
|
17
26
|
# register each provided handler
|
18
|
-
handlers.each do |
|
19
|
-
|
27
|
+
handlers.each do |handler|
|
28
|
+
iface_name = handler.class.to_s.split('::').last
|
29
|
+
server.add_handler iface_name, handler
|
20
30
|
end
|
21
31
|
|
22
|
-
post mount_path do
|
32
|
+
post options[:mount_path] do
|
23
33
|
request.body.rewind
|
24
34
|
resp = server.handle_json(request.body.read)
|
25
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barrister-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erin Swenson-Healey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: barrister
|