Class: Rack::RPC::Service
- Inherits:
-
Object
- Object
- Rack::RPC::Service
- Defined in:
- lib/rack/rpc/service.rb
Overview
Represents an RPC service.
Class Method Summary (collapse)
-
+ (Class) [](operator_name)
Returns the operator class for the given operator name.
-
+ operator(klass, options = {})
Defines an operator for this service class.
-
+ (Hash{Class => Hash}) operators
Returns the operator definitions for this service class.
Instance Method Summary (collapse)
- - method_missing(method_name, *args, &block) protected
-
- (Boolean) respond_to?(method_name)
true
orfalse
.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- method_missing(method_name, *args, &block) (protected)
This method returns an undefined value.
58 59 60 61 62 63 64 |
# 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 |
Class Method Details
+ (Class) [](operator_name)
Returns the operator class for the given operator name.
38 39 40 41 42 43 44 |
# File 'lib/rack/rpc/service.rb', line 38 def self.[](operator_name) operator_name = operator_name.to_sym operators.find do |klass, | klass_name = klass.name.split('::').last # TODO: optimize this return klass if operator_name.eql?(klass_name.to_sym) end end |
+ operator(klass, options = {})
This method returns an undefined value.
Defines an operator for this service class.
20 21 22 23 |
# File 'lib/rack/rpc/service.rb', line 20 def self.operator(klass, = {}) raise TypeError, "expected a Class, but got #{klass.inspect}" unless klass.is_a?(Class) operators[klass] ||= end |
+ (Hash{Class => Hash}) operators
Returns the operator definitions for this service class.
29 30 31 |
# File 'lib/rack/rpc/service.rb', line 29 def self.operators @operators ||= {} end |
Instance Method Details
- (Boolean) respond_to?(method_name)
Returns true
or false
49 50 51 |
# File 'lib/rack/rpc/service.rb', line 49 def respond_to?(method_name) super || (self.class[method_name] ? true : false) end |