class WebsocketRails::EventMap

Provides a DSL for mapping client events to controller actions.

Example events.rb file

# located in config/initializers/events.rb
WebsocketRails::EventMap.describe do
  subscribe :client_connected, to: ChatController, with_method: :client_connected
end

A single event can be mapped to any number of controller actions.

subscribe :new_message, :to => ChatController, :with_method => :rebroadcast_message
subscribe :new_message, :to => LogController, :with_method => :log_message

Events can be nested underneath namesapces.

namespace :product do
  subscribe :new, :to => ProductController, :with_method => :new
end

Attributes

namespace[R]

Public Class Methods

describe(&block) click to toggle source
# File lib/websocket_rails/event_map.rb, line 22
def self.describe(&block)
  WebsocketRails.config.route_block = block
end
new(dispatcher) click to toggle source
# File lib/websocket_rails/event_map.rb, line 28
def initialize(dispatcher)
  @dispatcher = dispatcher
  @namespace  = DSL.new(dispatcher).evaluate WebsocketRails.config.route_block
  @namespace  = DSL.new(dispatcher,@namespace).evaluate InternalEvents.events
end

Public Instance Methods

reload_controllers!() click to toggle source

Proxy the reload_controllers! method to the global namespace.

# File lib/websocket_rails/event_map.rb, line 39
def reload_controllers!
  @namespace.reload_controllers!
end
routes_for(event, &block) click to toggle source
# File lib/websocket_rails/event_map.rb, line 34
def routes_for(event, &block)
  @namespace.routes_for event, &block
end