Class: Rack::BertRpc

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bert_rpc.rb,
lib/rack/bert_rpc/mod.rb,
lib/rack/bert_rpc/server.rb,
lib/rack/bert_rpc/version.rb,
lib/rack/bert_rpc/encoding.rb,
lib/rack/bert_rpc/server_error.rb

Defined Under Namespace

Modules: Encoding Classes: Mod, Server, ServerError

Constant Summary collapse

VERSION =
"0.2.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ BertRpc

Returns a new instance of BertRpc.



21
22
23
24
25
26
27
28
29
30
# File 'lib/rack/bert_rpc.rb', line 21

def initialize(app, options = {})
  @path = options[:path] || '/rpc'
  @app = app
  @server = options[:server] || Server.new

  expose_defaults!
  options[:expose].each do |sym, mod|
    @server.expose(sym, mod)
  end unless options[:expose].nil?
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



19
20
21
# File 'lib/rack/bert_rpc.rb', line 19

def path
  @path
end

Class Method Details

.clear_exposedObject



14
15
16
# File 'lib/rack/bert_rpc.rb', line 14

def clear_exposed
  @exposed_modules = []
end

.expose(sym, mod) ⇒ Object



6
7
8
# File 'lib/rack/bert_rpc.rb', line 6

def expose(sym, mod)
  @exposed_modules << [sym, mod]
end

.exposed_modulesObject



10
11
12
# File 'lib/rack/bert_rpc.rb', line 10

def exposed_modules
  @exposed_modules ||= []
end

Instance Method Details

#call(env) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rack/bert_rpc.rb', line 32

def call(env)
  if path == env["PATH_INFO"]
    response = @server.handle(env["rack.input"])
    [200, { "Content-Type" => "application/bert" }, response]
  else
    @app.call(env)
  end
end