Class: Faye::Channel
- Inherits:
-
Object
- Object
- Faye::Channel
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .expand(name) ⇒ Object
- .meta?(name) ⇒ Boolean
- .parse(name) ⇒ Object
- .service?(name) ⇒ Boolean
- .subscribable?(name) ⇒ Boolean
- .unparse(segments) ⇒ Object
- .valid?(name) ⇒ Boolean
Instance Method Summary collapse
- #<<(message) ⇒ Object
-
#initialize(name) ⇒ Channel
constructor
A new instance of Channel.
- #unused? ⇒ Boolean
Methods included from Publisher
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
#name ⇒ Object (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 (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
61 62 63 64 |
# File 'lib/faye/protocol/channel.rb', line 61 def (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
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
71 72 73 74 |
# File 'lib/faye/protocol/channel.rb', line 71 def subscribable?(name) return nil unless valid?(name) not (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
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 <<() trigger(:message, ) end |
#unused? ⇒ Boolean
16 17 18 |
# File 'lib/faye/protocol/channel.rb', line 16 def unused? listener_count(:message).zero? end |