Sha256: cc377a7a34220eef856c6034e67e6e193e8aea020cabe17d12ee7fc0c794fd50

Contents?: true

Size: 942 Bytes

Versions: 28

Compression:

Stored size: 942 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
        # TODO: Log these errors better
        puts "ERROR: #{e.inspect}"
        puts e.backtrace
        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

28 entries across 28 versions & 1 rubygems

Version Path
volt-0.8.4 lib/volt/tasks/dispatcher.rb
volt-0.8.3 lib/volt/tasks/dispatcher.rb
volt-0.8.2 lib/volt/tasks/dispatcher.rb
volt-0.8.1 lib/volt/tasks/dispatcher.rb
volt-0.8.0 lib/volt/tasks/dispatcher.rb
volt-0.7.23 lib/volt/tasks/dispatcher.rb
volt-0.7.22 lib/volt/tasks/dispatcher.rb
volt-0.7.21 lib/volt/tasks/dispatcher.rb
volt-0.7.20 lib/volt/tasks/dispatcher.rb
volt-0.7.19 lib/volt/tasks/dispatcher.rb
volt-0.7.18 lib/volt/tasks/dispatcher.rb
volt-0.7.17 lib/volt/tasks/dispatcher.rb
volt-0.7.16 lib/volt/tasks/dispatcher.rb
volt-0.7.15 lib/volt/tasks/dispatcher.rb
volt-0.7.14 lib/volt/tasks/dispatcher.rb
volt-0.7.13 lib/volt/tasks/dispatcher.rb
volt-0.7.12 lib/volt/tasks/dispatcher.rb
volt-0.7.10 lib/volt/tasks/dispatcher.rb
volt-0.7.9 lib/volt/tasks/dispatcher.rb
volt-0.7.8 lib/volt/tasks/dispatcher.rb