Class: Faye::Channel

Inherits:
Object
  • Object
show all
Includes:
Publisher
Defined in:
lib/faye/protocol/channel.rb

Defined Under Namespace

Classes: Set

Constant Summary collapse

HANDSHAKE =
'/meta/handshake'
CONNECT =
'/meta/connect'
SUBSCRIBE =
'/meta/subscribe'
UNSUBSCRIBE =
'/meta/unsubscribe'
DISCONNECT =
'/meta/disconnect'
META =
'meta'
SERVICE =
'service'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Publisher

#unbind

Constructor Details

#initialize(name) ⇒ Channel

Returns a new instance of Channel.


7
8
9
10
# File 'lib/faye/protocol/channel.rb', line 7

def initialize(name)
  super()
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/faye/protocol/channel.rb', line 5

def name
  @name
end

Class Method Details

.expand(name) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/faye/protocol/channel.rb', line 30

def expand(name)
  segments = parse(name)
  channels = ['/**', name]

  copy = segments.dup
  copy[copy.size - 1] = '*'
  channels << unparse(copy)

  1.upto(segments.size - 1) do |i|
    copy = segments[0...i]
    copy << '**'
    channels << unparse(copy)
  end

  channels
end

.meta?(name) ⇒ Boolean

Returns:

  • (Boolean)

61
62
63
64
# File 'lib/faye/protocol/channel.rb', line 61

def meta?(name)
  segments = parse(name)
  segments ? (segments.first == META) : nil
end

.parse(name) ⇒ Object


52
53
54
55
# File 'lib/faye/protocol/channel.rb', line 52

def parse(name)
  return nil unless valid?(name)
  name.split('/')[1..-1]
end

.service?(name) ⇒ Boolean

Returns:

  • (Boolean)

66
67
68
69
# File 'lib/faye/protocol/channel.rb', line 66

def service?(name)
  segments = parse(name)
  segments ? (segments.first == SERVICE) : nil
end

.subscribable?(name) ⇒ Boolean

Returns:

  • (Boolean)

71
72
73
74
# File 'lib/faye/protocol/channel.rb', line 71

def subscribable?(name)
  return nil unless valid?(name)
  not meta?(name) and not service?(name)
end

.unparse(segments) ⇒ Object


57
58
59
# File 'lib/faye/protocol/channel.rb', line 57

def unparse(segments)
  '/' + segments.join('/')
end

.valid?(name) ⇒ Boolean

Returns:

  • (Boolean)

47
48
49
50
# File 'lib/faye/protocol/channel.rb', line 47

def valid?(name)
  Grammar::CHANNEL_NAME =~ name or
  Grammar::CHANNEL_PATTERN =~ name
end

Instance Method Details

#<<(message) ⇒ Object


12
13
14
# File 'lib/faye/protocol/channel.rb', line 12

def <<(message)
  trigger(:message, message)
end

#unused?Boolean

Returns:

  • (Boolean)

16
17
18
# File 'lib/faye/protocol/channel.rb', line 16

def unused?
  listener_count(:message).zero?
end