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

#bind, #count_listeners, #trigger, #unbind

Constructor Details

#initialize(name) ⇒ Channel

Returns a new instance of Channel.



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

def initialize(name)
  @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



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

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)


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

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

.parse(name) ⇒ Object



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

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

.service?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.subscribable?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.unparse(segments) ⇒ Object



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

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

.valid?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#<<(message) ⇒ Object



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

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

#unused?Boolean

Returns:

  • (Boolean)


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

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