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.3.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.



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

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

  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.



28
29
30
# File 'lib/rack/bert_rpc.rb', line 28

def path
  @path
end

Class Method Details

.clear_exposedObject



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

def clear_exposed
  @exposed_modules = []
end

.expose(sym, mod) ⇒ Object



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

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

.exposed_modulesObject



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

def exposed_modules
  @exposed_modules ||= []
end

.loggerObject



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

def logger
  @logger ||= ::Logger.new(STDOUT)
end

.logger=(logger) ⇒ Object



23
24
25
# File 'lib/rack/bert_rpc.rb', line 23

def logger=(logger)
  @logger = logger
end

Instance Method Details

#call(env) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/rack/bert_rpc.rb', line 42

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