Class: FayeRails::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/faye-rails/filter.rb

Defined Under Namespace

Classes: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel = '/**', direction = :any, block) ⇒ Filter

Create a new FayeRails::Filter which can be passed to Faye::RackAdapter#add_extension.

Parameters:

  • channel (defaults to: '/**')

    Optional channel name to limit messages to.

  • direction (defaults to: :any)

    :in, :out or :any.

  • block

    A proc object to be called when filtering messages.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/faye-rails/filter.rb', line 17

def initialize(channel='/**', direction=:any, block)
  @channel = channel
  @block = block
  raise ArgumentError, "Block cannot be nil" unless block
  if (direction == :in) || (direction == :any)
    @in_filter = DSL
  end
  if (direction == :out) || (direction == :any)
    @out_filter = DSL
  end
end

Instance Attribute Details

#channelObject (readonly)

Returns the value of attribute channel.



5
6
7
# File 'lib/faye-rails/filter.rb', line 5

def channel
  @channel
end

#loggerObject



39
40
41
42
43
# File 'lib/faye-rails/filter.rb', line 39

def logger
  if defined?(::Rails)
    @logger ||= Rails.logger
  end
end

#serverObject

Returns the value of attribute server.



4
5
6
# File 'lib/faye-rails/filter.rb', line 4

def server
  @server
end

Instance Method Details

#destroyObject



54
55
56
57
58
# File 'lib/faye-rails/filter.rb', line 54

def destroy
  if server
    server.remove_extension(self)
  end
end

#incoming(message, callback) ⇒ Object



45
46
47
# File 'lib/faye-rails/filter.rb', line 45

def incoming(message, callback)
  @in_filter.new(@block, message, channel, callback, :incoming) if @in_filter
end

#outgoing(message, callback) ⇒ Object



50
51
52
# File 'lib/faye-rails/filter.rb', line 50

def outgoing(message, callback)
  @out_filter.new(@block, message, channel, callback, :outgoing) if @out_filter
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
# File 'lib/faye-rails/filter.rb', line 29

def respond_to?(method)
  if (method == :incoming) 
    !!@in_filter
  elsif (method == :outgoing)
    !!@out_filter
  else
    super
  end
end