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.
56 57 58 59 |
# File 'lib/rack/rpc/server.rb', line 56 def initialize( = {}, &block) @options = .dup block.call(self) if block_given? end |
Instance Attribute Details
#options ⇒ Hash (readonly)
49 50 51 |
# File 'lib/rack/rpc/server.rb', line 49 def @options end |
#request ⇒ Rack::Request
52 53 54 |
# File 'lib/rack/rpc/server.rb', line 52 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
44 45 46 |
# File 'lib/rack/rpc/server.rb', line 44 def self.after_filter(method_sym = nil, = {}, &block) setup_hook(:after, method_sym, , block) end |
.before_filter(method_sym = nil, options = {}, &block) ⇒ Object
40 41 42 |
# File 'lib/rack/rpc/server.rb', line 40 def self.before_filter(method_sym = nil, = {}, &block) setup_hook(:before, method_sym, , block) end |
.hooks ⇒ Object
36 37 38 |
# File 'lib/rack/rpc/server.rb', line 36 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 34 |
# 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)} method = :"#{server_method}_without_callbacks" out = args.any? ? self.send(method, *args) : self.send(method) self.class.hooks[:after].each{|command| command.call(self) if command.callable?(server_method)} out end end end end |