2015-07-05 16:34:23 -04:00
module ActionCable
module Server
2016-02-13 21:05:04 -05:00
# An instance of this configuration object is available via ActionCable.server.config, which allows you to tweak Action Cable configuration
2015-07-07 17:13:00 -04:00
# in a Rails config initializer.
2015-07-05 16:34:23 -04:00
class Configuration
attr_accessor :logger , :log_tags
2016-03-01 19:50:19 -05:00
attr_accessor :use_faye , :connection_class , :worker_pool_size
2015-10-07 12:24:20 -04:00
attr_accessor :disable_request_forgery_protection , :allowed_request_origins
2016-02-04 22:33:46 -05:00
attr_accessor :cable , :url , :mount_path
2015-07-05 16:34:23 -04:00
2016-02-05 16:48:48 -05:00
attr_accessor :channel_paths # :nodoc:
2015-07-05 16:34:23 -04:00
def initialize
@log_tags = [ ]
2016-02-05 16:56:52 -05:00
@connection_class = ActionCable :: Connection :: Base
@worker_pool_size = 100
2015-07-05 16:34:23 -04:00
2015-10-07 12:24:20 -04:00
@disable_request_forgery_protection = false
2015-07-05 16:34:23 -04:00
end
def channel_class_names
@channel_class_names || = channel_paths . collect do | channel_path |
Pathname . new ( channel_path ) . basename . to_s . split ( '.' ) . first . camelize
end
end
2016-01-06 17:16:02 -05:00
2016-01-16 10:33:50 -05:00
# Returns constant of subscription adapter specified in config/cable.yml.
# If the adapter cannot be found, this will default to the Redis adapter.
# Also makes sure proper dependencies are required.
def pubsub_adapter
adapter = ( cable . fetch ( 'adapter' ) { 'redis' } )
path_to_adapter = " action_cable/subscription_adapter/ #{ adapter } "
begin
require path_to_adapter
rescue Gem :: LoadError = > e
raise Gem :: LoadError , " Specified ' #{ adapter } ' for Action Cable pubsub adapter, but the gem is not loaded. Add `gem ' #{ e . name } '` to your Gemfile (and ensure its version is at the minimum required by Action Cable). "
rescue LoadError = > e
raise LoadError , " Could not load ' #{ path_to_adapter } '. Make sure that the adapter in config/cable.yml is valid. If you use an adapter other than 'postgresql' or 'redis' add the necessary adapter gem to the Gemfile. " , e . backtrace
end
2016-01-20 00:33:13 -05:00
adapter = adapter . camelize
2016-01-15 19:07:18 -05:00
adapter = 'PostgreSQL' if adapter == 'Postgresql'
" ActionCable::SubscriptionAdapter:: #{ adapter } " . constantize
2016-01-06 17:16:02 -05:00
end
2016-03-01 19:50:19 -05:00
def event_loop_class
if use_faye
ActionCable :: Connection :: FayeEventLoop
else
ActionCable :: Connection :: StreamEventLoop
end
end
def client_socket_class
if use_faye
ActionCable :: Connection :: FayeClientSocket
else
ActionCable :: Connection :: ClientSocket
end
end
2015-07-05 16:34:23 -04:00
end
end
end