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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 533384ba51e4ec858ef745450dddced1672c6eb9
4
- data.tar.gz: 3f45d6c74203dad7d99e28de55f1dbc843f3f336
3
+ metadata.gz: f1c0cfd8b70cf885a4149b72195397cbb74fc364
4
+ data.tar.gz: 5734c4b907037de4b38dc52c5d8b8060ca505d91
5
5
  SHA512:
6
- metadata.gz: 49ff9a3b2ce66adf4ba6718021644e2d753b11666bc44bf0a9474823bd8818b39b0bca702c268fb1cb883d750c8cbb07235cec5095572add9357bddd44a21af9
7
- data.tar.gz: 58e1bcdae9eeeb446e55723301d83a5766240cad7c1d467bc00371b6d647c7bd1e0798f9004de6cec86030d251817da924c9dc669e8a156ff76a74299d0560aa
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 )
@@ -6,20 +6,30 @@ module Barrister
6
6
 
7
7
  class SinatraContainer
8
8
 
9
- def initialize(json_path, mount_path, handlers, port=4567, host='localhost')
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 |handler_klass|
19
- server.add_handler handler_klass.to_s, handler_klass.new
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
 
@@ -1,5 +1,5 @@
1
1
  module Barrister
2
2
  module Sinatra
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
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.2
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-02-26 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: barrister