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.
93 94 95 96 |
# File 'lib/faye-rails/rack_adapter.rb', line 93 def initialize @default = :allow @mappings = {} end |
Instance Method Details
#allow_unknown_channels! ⇒ Object
128 129 130 |
# File 'lib/faye-rails/rack_adapter.rb', line 128 def allow_unknown_channels! @default = :allow end |
#block_unknown_channels! ⇒ Object
120 121 122 |
# File 'lib/faye-rails/rack_adapter.rb', line 120 def block_unknown_channels! @default = :block end |
#drop_unknown_channels! ⇒ Object
124 125 126 |
# File 'lib/faye-rails/rack_adapter.rb', line 124 def drop_unknown_channels! @default = :drop end |
#incoming(message, callback) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/faye-rails/rack_adapter.rb', line 98 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
112 113 114 115 116 117 118 |
# File 'lib/faye-rails/rack_adapter.rb', line 112 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
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/faye-rails/rack_adapter.rb', line 132 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 |