class Rack::RPC::Service
Represents an RPC
service.
Public Class Methods
[](operator_name)
click to toggle source
Returns the operator class for the given operator name.
@param [Symbol, to_sym] operator_name @return [Class]
# File lib/rack/rpc/service.rb, line 38 def self.[](operator_name) operator_name = operator_name.to_sym operators.find do |klass, options| klass_name = klass.name.split('::').last # TODO: optimize this return klass if operator_name.eql?(klass_name.to_sym) end end
operator(klass, options = {})
click to toggle source
Defines an operator for this service class.
@example
class Calculator < Service operator Add operator Subtract operator Multiply operator Divide end
@param [Class] klass @param [Hash{Symbol => Object}] options @return [void]
# File lib/rack/rpc/service.rb, line 20 def self.operator(klass, options = {}) raise TypeError, "expected a Class, but got #{klass.inspect}" unless klass.is_a?(Class) operators[klass] ||= options end
operators()
click to toggle source
Returns the operator definitions for this service class.
@return [Hash{Class => Hash}]
# File lib/rack/rpc/service.rb, line 29 def self.operators @operators ||= {} end
Public Instance Methods
respond_to?(method_name)
click to toggle source
@param [Symbol, to_sym] method_name @return [Boolean] `true` or `false`
Calls superclass method
# File lib/rack/rpc/service.rb, line 49 def respond_to?(method_name) super || (self.class[method_name] ? true : false) end
Protected Instance Methods
method_missing(method_name, *args, &block)
click to toggle source
@param [Symbol, to_sym] method_name @param [Array] args @return [void] @raise [NoMethodError] if `self` doesn't respond to `method_name`
Calls superclass method
# File lib/rack/rpc/service.rb, line 58 def method_missing(method_name, *args, &block) if (operator = self.class[method_name]).nil? super # raises NoMethodError else operator.new(args).execute end end