Sha256: 64c19fe97f2a6aab3d183d84455937e2185f20b3f73ac779744fc4dbaa48e507

Contents?: true

Size: 859 Bytes

Versions: 25

Compression:

Stored size: 859 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
      begin
        result = klass.new(channel, self).send(method_name, *args)
        error = nil
      rescue => e
        result = nil
        error = e
      end
      
      if callback_id
        # Callback with result
        channel.send_message('response', callback_id, result, error)
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
volt-0.5.18 lib/volt/tasks/dispatcher.rb
volt-0.5.17 lib/volt/tasks/dispatcher.rb
volt-0.5.16 lib/volt/tasks/dispatcher.rb
volt-0.5.15 lib/volt/tasks/dispatcher.rb
volt-0.5.14 lib/volt/tasks/dispatcher.rb
volt-0.5.13 lib/volt/tasks/dispatcher.rb
volt-0.5.12 lib/volt/tasks/dispatcher.rb
volt-0.5.11 lib/volt/tasks/dispatcher.rb
volt-0.5.10 lib/volt/tasks/dispatcher.rb
volt-0.5.9 lib/volt/tasks/dispatcher.rb
volt-0.5.8 lib/volt/tasks/dispatcher.rb
volt-0.5.7 lib/volt/tasks/dispatcher.rb
volt-0.5.6 lib/volt/tasks/dispatcher.rb
volt-0.5.4 lib/volt/tasks/dispatcher.rb
volt-0.5.3 lib/volt/tasks/dispatcher.rb
volt-0.5.2 lib/volt/tasks/dispatcher.rb
volt-0.5.1 lib/volt/tasks/dispatcher.rb
volt-0.5.0 lib/volt/tasks/dispatcher.rb
volt-0.4.18 lib/volt/tasks/dispatcher.rb
volt-0.4.17 lib/volt/tasks/dispatcher.rb