Class: FayeRails::RackAdapter

Inherits:
Faye::RackAdapter
  • Object
show all
Defined in:
lib/faye-rails/rack_adapter.rb

Defined Under Namespace

Classes: DebugMessagesExtension, RoutingExtension

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RackAdapter) initialize(app = nil, options = nil)

Returns a new instance of RackAdapter



8
9
10
11
# File 'lib/faye-rails/rack_adapter.rb', line 8

def initialize(app=nil, options=nil)
  super
  FayeRails.servers << self
end

Instance Attribute Details

- (Object) endpoint (readonly)

Returns the value of attribute endpoint



6
7
8
# File 'lib/faye-rails/rack_adapter.rb', line 6

def endpoint
  @endpoint
end

- (Object) server (readonly)

Returns the value of attribute server



6
7
8
# File 'lib/faye-rails/rack_adapter.rb', line 6

def server
  @server
end

Instance Method Details

- (Object) debug_messages

Adds a very simple extension to the server causing it to log all messages in and out to Rails.logger.debug.



63
64
65
# File 'lib/faye-rails/rack_adapter.rb', line 63

def debug_messages
  add_extension(DebugMessagesExtension.new)
end

- (Object) listen(port, ssl_options = nil)



13
14
15
16
17
18
19
20
# File 'lib/faye-rails/rack_adapter.rb', line 13

def listen(port, ssl_options = nil)
  if defined? ::Rails
    Faye.ensure_reactor_running!
    super
  else
    super
  end
end

- (Object) map(opts)

Rudimentary routing support for channels to controllers.

Parameters:

  • opts

    a Hash of mappings either string keys (channel globs) mapping to controller constants eg:

    '/widgets/**' => WidgetsController

    or you can set the behaviour for unknown channels:

    :default => :block

    :default can be set to :allow, :drop or :block. if :drop is chosen then messages to unknown channels will be silently dropped, whereas if you choose :block then the message will be returned with the error “Permission denied.”



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/faye-rails/rack_adapter.rb', line 39

def map(opts)
  if opts.is_a? Hash
    opts.each do |channel, controller|
      if channel.is_a? String
        if File.fnmatch?('/**', channel)
          routing_extension.map(channel, controller)
        else
          raise ArgumentError, "Invalid channel: #{channel}"
        end
      elsif channel == :default
        if controller == :block
          routing_extension.block_unknown_channels!
        elsif controller == :drop
          routing_extension.drop_unknown_channels!
        elsif controller == :allow
          routing_extension.allow_unknown_channels!
        end
      end
    end
  end
end