Class: Rack::RPC::Server
- Inherits:
-
Object
- Object
- Rack::RPC::Server
- Defined in:
- lib/rack/rpc/server.rb
Overview
A base class for RPC servers.
Instance Attribute Summary collapse
- #options ⇒ Hash readonly
- #request ⇒ Rack::Request
Class Method Summary collapse
- .[](rpc_method_name) ⇒ Object
- .after_filter(method_sym = nil, options = {}, &block) ⇒ Object
- .before_filter(method_sym = nil, options = {}, &block) ⇒ Object
- .hooks ⇒ Object
- .rpc(mappings = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(options = {}, &block) ⇒ Server
Returns a new instance of Server.
55 56 57 58 |
# File 'lib/rack/rpc/server.rb', line 55 def initialize( = {}, &block) @options = .dup block.call(self) if block_given? end |
Instance Attribute Details
#options ⇒ Hash (readonly)
48 49 50 |
# File 'lib/rack/rpc/server.rb', line 48 def @options end |
#request ⇒ Rack::Request
51 52 53 |
# File 'lib/rack/rpc/server.rb', line 51 def request @request end |
Class Method Details
.[](rpc_method_name) ⇒ Object
7 8 9 10 |
# File 'lib/rack/rpc/server.rb', line 7 def self.[](rpc_method_name) @mappings ||= {} @mappings[rpc_method_name] end |
.after_filter(method_sym = nil, options = {}, &block) ⇒ Object
43 44 45 |
# File 'lib/rack/rpc/server.rb', line 43 def self.after_filter(method_sym = nil, = {}, &block) setup_hook(:after, method_sym, , block) end |
.before_filter(method_sym = nil, options = {}, &block) ⇒ Object
39 40 41 |
# File 'lib/rack/rpc/server.rb', line 39 def self.before_filter(method_sym = nil, = {}, &block) setup_hook(:before, method_sym, , block) end |
.hooks ⇒ Object
35 36 37 |
# File 'lib/rack/rpc/server.rb', line 35 def self.hooks @hooks ||= {:before => [], :after => []} end |
.rpc(mappings = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rack/rpc/server.rb', line 14 def self.rpc(mappings = {}) @mappings ||= {} if mappings.empty? @mappings else # Store the mappings @mappings.merge!(mappings) # Wrap each method so we can inject before and after callbacks mappings.each do |rpc_method_name, server_method| self.send(:alias_method, :"#{server_method}_without_callbacks", server_method.to_sym) self.send(:define_method, server_method) do |*args| self.class.hooks[:before].each{|command| command.call(self) if command.callable?(server_method)} out = self.send(:"#{server_method}_without_callbacks", *args) self.class.hooks[:after].each{|command| command.call(self) if command.callable?(server_method)} out end end end end |