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.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BertRpc.



7
8
9
10
11
12
13
14
# File 'lib/rack/bert_rpc.rb', line 7

def initialize(app, options = {})
  @path = options[:path] || '/rpc'
  @app = app
  @server = options[:server] || Server.new
  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.



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

def path
  @path
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/rack/bert_rpc.rb', line 16

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