2015-07-05 16:34:23 -04:00
|
|
|
module ActionCable
|
|
|
|
module Server
|
2015-07-07 17:13:00 -04:00
|
|
|
# An instance of this configuration object is available via ActionCable.server.config, which allows you to tweak the configuration points
|
|
|
|
# in a Rails config initializer.
|
2015-07-05 16:34:23 -04:00
|
|
|
class Configuration
|
|
|
|
attr_accessor :logger, :log_tags
|
|
|
|
attr_accessor :connection_class, :worker_pool_size
|
2016-01-06 17:16:02 -05:00
|
|
|
attr_accessor :channels_path
|
2015-10-07 12:24:20 -04:00
|
|
|
attr_accessor :disable_request_forgery_protection, :allowed_request_origins
|
2016-01-15 17:26:17 -05:00
|
|
|
attr_accessor :cable, :url
|
2015-07-05 16:34:23 -04:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@log_tags = []
|
|
|
|
|
|
|
|
@connection_class = ApplicationCable::Connection
|
|
|
|
@worker_pool_size = 100
|
|
|
|
|
|
|
|
@channels_path = Rails.root.join('app/channels')
|
2015-10-07 12:24:20 -04:00
|
|
|
|
|
|
|
@disable_request_forgery_protection = false
|
2015-07-05 16:34:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def channel_paths
|
|
|
|
@channels ||= Dir["#{channels_path}/**/*_channel.rb"]
|
|
|
|
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-15 19:07:18 -05:00
|
|
|
# Returns constant of subscription adapter specified in config/cable.yml
|
2016-01-06 17:16:02 -05:00
|
|
|
# If the adapter cannot be found, this will default to the Redis adapter
|
2016-01-15 19:07:18 -05:00
|
|
|
def subscription_adapter
|
2016-01-07 09:37:41 -05:00
|
|
|
# Defaults to redis if no adapter is set
|
2016-01-15 17:26:17 -05:00
|
|
|
adapter = cable.fetch('adapter') { 'redis' }
|
2016-01-15 19:07:18 -05:00
|
|
|
adapter.camelize
|
|
|
|
adapter = 'PostgreSQL' if adapter == 'Postgresql'
|
|
|
|
"ActionCable::SubscriptionAdapter::#{adapter}".constantize
|
2016-01-06 17:16:02 -05:00
|
|
|
end
|
2015-07-05 16:34:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|