Sha256: fed51701b1b4feba852edcb2258807d3f333282550ee80e189fa69a822effaf8

Contents?: true

Size: 751 Bytes

Versions: 2

Compression:

Stored size: 751 Bytes

Contents

# The task dispatcher is responsible for taking incoming messages
# from the socket channel and dispatching them to the proper handler.
class Dispatcher
  
  def dispatch(channel, message)
    callback_id, class_name, method_name, *args = message

    # TODO: Think about security?
    if class_name[/Tasks$/] && !class_name['::']
      # TODO: Improve error on a class we don't have
      require(class_name.underscore)
    
      # Get the class
      klass = Object.send(:const_get, class_name)
      
      # Init and send the method
      result = klass.new(channel, self).send(method_name, *args)
      
      if callback_id
        # Callback with result
        channel.send_message('response', callback_id, result)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
volt-0.4.9 lib/volt/tasks/dispatcher.rb
volt-0.4.8 lib/volt/tasks/dispatcher.rb