rack-bert-rpc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -49,6 +49,16 @@ The `BertRpc` middle takes several configuration parameters:
49
49
  Used for testing, switches out the backend `BertRpc::Server` so the
50
50
  requests can be handled by a different one
51
51
 
52
+ Modules can also be exposed through class level methods on
53
+ `Rack::BertRpc`. For example:
54
+
55
+ Rack::BertRpc.expose(:mod, Mod)
56
+
57
+ exposes the module `Mod` as `:mod`. This list of exposed modules can
58
+ be cleared using `Rack::BertRpc#clear_exposed`. Note: this will only
59
+ clear modules listed through `Rack::BertRpc#expose`, not those exposed
60
+ through the Rack configuration.
61
+
52
62
  Example
53
63
  -------
54
64
 
data/lib/rack/bert_rpc.rb CHANGED
@@ -2,12 +2,28 @@ require 'rack'
2
2
 
3
3
  module Rack
4
4
  class BertRpc
5
+ class << self
6
+ def expose(sym, mod)
7
+ @exposed_modules << [sym, mod]
8
+ end
9
+
10
+ def exposed_modules
11
+ @exposed_modules ||= []
12
+ end
13
+
14
+ def clear_exposed
15
+ @exposed_modules = []
16
+ end
17
+ end
18
+
5
19
  attr_reader :path
6
20
 
7
21
  def initialize(app, options = {})
8
22
  @path = options[:path] || '/rpc'
9
23
  @app = app
10
24
  @server = options[:server] || Server.new
25
+
26
+ expose_defaults!
11
27
  options[:expose].each do |sym, mod|
12
28
  @server.expose(sym, mod)
13
29
  end unless options[:expose].nil?
@@ -21,6 +37,14 @@ module Rack
21
37
  @app.call(env)
22
38
  end
23
39
  end
40
+
41
+ private
42
+
43
+ def expose_defaults!
44
+ BertRpc.exposed_modules.each do |sym, mod|
45
+ @server.expose(sym, mod)
46
+ end
47
+ end
24
48
  end
25
49
  end
26
50
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class BertRpc
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Burrows
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-12 00:00:00 -07:00
17
+ date: 2010-08-13 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency