aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/server/configuration.rb
blob: 5d65f5e0e94941f05ceddd1ea38e873a3b16dff2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module ActionCable
  module Server
    # 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.
    class Configuration
      attr_accessor :logger, :log_tags
      attr_accessor :connection_class, :worker_pool_size
      attr_accessor :redis, :channels_path
      attr_accessor :disable_request_forgery_protection, :allowed_request_origins
      attr_accessor :url

      def initialize
        @log_tags = []

        @connection_class  = ApplicationCable::Connection
        @worker_pool_size  = 100

        @channels_path = Rails.root.join('app/channels')

        @disable_request_forgery_protection = false
      end

      def log_to_stdout
        console = ActiveSupport::Logger.new($stdout)
        console.formatter = @logger.formatter
        console.level = @logger.level

        @logger.extend(ActiveSupport::Logger.broadcast(console))
      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
    end
  end
end