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
-
.[](operator_name) ⇒ Class
Returns the operator class for the given operator name.
-
.operator(klass, options = {}) ⇒ void
Defines an operator for this service class.
-
.operators ⇒ Hash{Class => Hash}
Returns the operator definitions for this service class.
Instance Method Summary collapse
-
#respond_to?(method_name) ⇒ Boolean
‘true` or `false`.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ void (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
.[](operator_name) ⇒ Class
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 = {}) ⇒ void
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 |
.operators ⇒ Hash{Class => Hash}
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
#respond_to?(method_name) ⇒ Boolean
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 |