Class: Faye::Channel

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

Defined Under Namespace

Classes: Tree

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

#add_subscriber, #count_subscribers, #publish_event, #remove_subscriber

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

.meta?(name) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/faye/protocol/channel.rb', line 35

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

.parse(name) ⇒ Object



30
31
32
33
# File 'lib/faye/protocol/channel.rb', line 30

def parse(name)
  return nil unless valid?(name)
  name.split('/')[1..-1].map { |s| s.to_sym }
end

.service?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/faye/protocol/channel.rb', line 40

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

.subscribable?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.valid?(name) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/faye/protocol/channel.rb', line 25

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)
  publish_event(:message, message)
end