Class: Twirp::Rails::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/twirp/rails/dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(service_class) ⇒ Dispatcher

Returns a new instance of Dispatcher.



6
7
8
9
10
11
12
13
14
# File 'lib/twirp/rails/dispatcher.rb', line 6

def initialize(service_class)
  # Check for a handler in the service's namespace, or in the root namespace
  # e.g. Twirp::Example::Cobbler::CobblerHandler or ::CobblerHandler
  @service_handler = if Object.const_defined?("#{service_class.module_parent}::#{service_class.service_name}Handler")
    "#{service_class.module_parent}::#{service_class.service_name}Handler".constantize
  else
    "#{service_class.service_name}Handler".constantize
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



20
21
22
23
24
# File 'lib/twirp/rails/dispatcher.rb', line 20

def method_missing(name, *args)
  request = args[0]
  env = args[1]
  @service_handler.new.process(name, request, env)
end

Instance Method Details

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/twirp/rails/dispatcher.rb', line 16

def respond_to_missing?(method, *)
  true
end