Class: FayeRails::Filter::DSL
- Inherits:
-
Object
- Object
- FayeRails::Filter::DSL
- Defined in:
- lib/faye-rails/filter.rb
Instance Attribute Summary (collapse)
-
- (Object) callback
readonly
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
-
- (Object) channel
readonly
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
-
- (Object) direction
readonly
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
-
- (Object) message
readonly
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
-
- (Object) original_message
readonly
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
Instance Method Summary (collapse)
-
- (Object) block(reason = "Message blocked by filter")
Syntactic sugar around callback.call which adds an error message to the message and passes it back to Faye, which will send back a rejection message to the sending client.
- - (Boolean) channel_matches?(glob, test)
- - (Boolean) client_id?(x = nil)
- - (Object) data
- - (Boolean) data?
-
- (Object) drop
Syntactic sugar around callback.call which returns nil to Faye - effectively dropping the message.
- - (Boolean) incoming? (also: #in?)
-
- (DSL) initialize(block, message, channel = '/**', callback, direction)
constructor
Called by FayeRails::Filter when Faye passes messages in for evaluation.
- - (Boolean) meta?
-
- (Object) modify(new_message)
Syntactic sugar around callback.call which passes the passed argument back to Faye in place of the original message.
- - (Boolean) outgoing? (also: #out?)
-
- (Object) pass
Syntactic sugar around callback.call which passes back the original message unmodified.
- - (Boolean) service?
-
- (Boolean) subscribing?
Easier than testing message every time.
- - (Boolean) subscription?(channel)
- - (Boolean) unsubscribing?
Constructor Details
- (DSL) initialize(block, message, channel = '/**', callback, direction)
Called by FayeRails::Filter when Faye passes messages in for evaluation.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/faye-rails/filter.rb', line 75 def initialize(block, , channel='/**', callback, direction) raise ArgumentError, "Block cannot be nil" unless block @channel = channel @original_message = .dup @message = @callback = callback @direction = direction if channel_matches?(@channel, @original_message['channel']) || (subscribing? && subscription?(@channel)) || (unsubscribing? && subscription?(@channel)) instance_eval(&block) else pass end end |
Instance Attribute Details
- (Object) callback (readonly)
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
66 67 68 |
# File 'lib/faye-rails/filter.rb', line 66 def callback @callback end |
- (Object) channel (readonly)
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
66 67 68 |
# File 'lib/faye-rails/filter.rb', line 66 def channel @channel end |
- (Object) direction (readonly)
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
66 67 68 |
# File 'lib/faye-rails/filter.rb', line 66 def direction @direction end |
- (Object) message (readonly)
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
66 67 68 |
# File 'lib/faye-rails/filter.rb', line 66 def @message end |
- (Object) original_message (readonly)
A small wrapper class around filter blocks to add some sugar to ease filter (Faye extension) creation.
66 67 68 |
# File 'lib/faye-rails/filter.rb', line 66 def @original_message end |
Instance Method Details
- (Object) block(reason = "Message blocked by filter")
Syntactic sugar around callback.call which adds an error message to the message and passes it back to Faye, which will send back a rejection message to the sending client.
164 165 166 167 168 |
# File 'lib/faye-rails/filter.rb', line 164 def block(reason="Message blocked by filter") = ['error'] = reason callback.call() end |
- (Boolean) channel_matches?(glob, test)
135 136 137 |
# File 'lib/faye-rails/filter.rb', line 135 def channel_matches?(glob,test) File.fnmatch? glob, test end |
- (Boolean) client_id?(x = nil)
127 128 129 130 131 132 133 |
# File 'lib/faye-rails/filter.rb', line 127 def client_id?(x=nil) if !!x ['client_id'] == x else !!['client_id'] end end |
- (Object) data
119 120 121 |
# File 'lib/faye-rails/filter.rb', line 119 def data ['data'] end |
- (Boolean) data?
123 124 125 |
# File 'lib/faye-rails/filter.rb', line 123 def data? !!data end |
- (Object) drop
Syntactic sugar around callback.call which returns nil to Faye - effectively dropping the message.
172 173 174 |
# File 'lib/faye-rails/filter.rb', line 172 def drop callback.call(nil) end |
- (Boolean) incoming? Also known as: in?
109 110 111 |
# File 'lib/faye-rails/filter.rb', line 109 def incoming? direction == :incoming end |
- (Boolean) meta?
101 102 103 |
# File 'lib/faye-rails/filter.rb', line 101 def ['channel'][0..5] == '/meta/' end |
- (Object) modify(new_message)
Syntactic sugar around callback.call which passes the passed argument back to Faye in place of the original message.
154 155 156 |
# File 'lib/faye-rails/filter.rb', line 154 def modify() callback.call() end |
- (Boolean) outgoing? Also known as: out?
114 115 116 |
# File 'lib/faye-rails/filter.rb', line 114 def outgoing? direction == :outgoing end |
- (Object) pass
Syntactic sugar around callback.call which passes back the original message unmodified.
145 146 147 |
# File 'lib/faye-rails/filter.rb', line 145 def pass callback.call() end |
- (Boolean) service?
105 106 107 |
# File 'lib/faye-rails/filter.rb', line 105 def service? ['channel'][0..8] == '/service/' end |
- (Boolean) subscribing?
Easier than testing message every time
93 94 95 |
# File 'lib/faye-rails/filter.rb', line 93 def subscribing? ['channel'] == '/meta/subscribe' end |
- (Boolean) subscription?(channel)
139 140 141 |
# File 'lib/faye-rails/filter.rb', line 139 def subscription?(channel) ['subscription'] && channel_matches?(channel, ['subscription']) end |
- (Boolean) unsubscribing?
97 98 99 |
# File 'lib/faye-rails/filter.rb', line 97 def unsubscribing? ['channel'] == '/meta/unsubscribe' end |