Class: FayeRails::RackAdapter::RoutingExtension
- Inherits:
-
Object
- Object
- FayeRails::RackAdapter::RoutingExtension
- Defined in:
- lib/faye-rails/rack_adapter.rb
Instance Method Summary collapse
- #allow_unknown_channels! ⇒ Object
- #block_unknown_channels! ⇒ Object
- #drop_unknown_channels! ⇒ Object
- #incoming(message, callback) ⇒ Object
-
#initialize ⇒ RoutingExtension
constructor
A new instance of RoutingExtension.
- #map(channel, controller) ⇒ Object
- #take_action_for(message, callback, test = '') ⇒ Object
Constructor Details
#initialize ⇒ RoutingExtension
Returns a new instance of RoutingExtension.
102 103 104 105 |
# File 'lib/faye-rails/rack_adapter.rb', line 102 def initialize @default = :allow @mappings = {} end |
Instance Method Details
#allow_unknown_channels! ⇒ Object
137 138 139 |
# File 'lib/faye-rails/rack_adapter.rb', line 137 def allow_unknown_channels! @default = :allow end |
#block_unknown_channels! ⇒ Object
129 130 131 |
# File 'lib/faye-rails/rack_adapter.rb', line 129 def block_unknown_channels! @default = :block end |
#drop_unknown_channels! ⇒ Object
133 134 135 |
# File 'lib/faye-rails/rack_adapter.rb', line 133 def drop_unknown_channels! @default = :drop end |
#incoming(message, callback) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/faye-rails/rack_adapter.rb', line 107 def incoming(, callback) if ['channel'] == '/meta/subscribe' take_action_for , callback, ['subscription'] elsif ['channel'] == '/meta/unsubscribe' take_action_for , callback, ['subscription'] elsif FayeRails::Matcher.match? '/meta/*', ['channel'] callback.call() elsif FayeRails::Matcher.match? '/service/**', ['channel'] callback.call() else take_action_for , callback, ['channel'] end end |
#map(channel, controller) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/faye-rails/rack_adapter.rb', line 121 def map(channel, controller) if FayeRails::Matcher.match? '/**', channel (@mappings[channel] ||= []) << controller else raise ArgumentError, "Invalid channel name: #{channel}" end end |
#take_action_for(message, callback, test = '') ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/faye-rails/rack_adapter.rb', line 141 def take_action_for(, callback, test='') if @mappings.keys.select { |glob| FayeRails::Matcher.match? glob, test }.size > 0 callback.call() elsif @default == :block ['error'] = "Permission denied" callback.call() elsif @default == :drop callback.call(nil) elsif @default == :allow callback.call() else callback.call(nil) end end |