From 661298176c72eefc6d0f42b58210119e76962364 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Fri, 5 Feb 2016 22:48:48 +0100 Subject: Inject Rails' channel paths in engine. We were explicitly referencing Rails.root in ActionCable::Server::Configuration.initialize, thereby coupling ourselves to Rails. Instead add `app/channels` to Rails' app paths and assign the existent files to `channel_paths`. Users can still append to those load paths with `<<` and `push` in `config/application.rb`. This means we can remove the custom `Dir` lookup in `channel_paths` and the Rails and root definitions in the tests. --- actioncable/lib/action_cable/engine.rb | 2 ++ actioncable/lib/action_cable/server/configuration.rb | 11 ++--------- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'actioncable/lib/action_cable') diff --git a/actioncable/lib/action_cable/engine.rb b/actioncable/lib/action_cable/engine.rb index f5e233e091..acca3961d8 100644 --- a/actioncable/lib/action_cable/engine.rb +++ b/actioncable/lib/action_cable/engine.rb @@ -31,6 +31,8 @@ module ActionCable self.cable = Rails.application.config_for(config_path).with_indifferent_access end + self.channel_paths = Rails.application.paths['app/channels'].existent + options.each { |k,v| send("#{k}=", v) } end end diff --git a/actioncable/lib/action_cable/server/configuration.rb b/actioncable/lib/action_cable/server/configuration.rb index 9a248933c4..019a374734 100644 --- a/actioncable/lib/action_cable/server/configuration.rb +++ b/actioncable/lib/action_cable/server/configuration.rb @@ -5,27 +5,20 @@ module ActionCable class Configuration attr_accessor :logger, :log_tags attr_accessor :connection_class, :worker_pool_size - attr_accessor :channel_load_paths attr_accessor :disable_request_forgery_protection, :allowed_request_origins attr_accessor :cable, :url + attr_accessor :channel_paths # :nodoc: + def initialize @log_tags = [] @connection_class = ApplicationCable::Connection @worker_pool_size = 100 - @channel_load_paths = [Rails.root.join('app/channels')] - @disable_request_forgery_protection = false end - def channel_paths - @channel_paths ||= channel_load_paths.flat_map do |path| - Dir["#{path}/**/*_channel.rb"] - end - end - def channel_class_names @channel_class_names ||= channel_paths.collect do |channel_path| Pathname.new(channel_path).basename.to_s.split('.').first.camelize -- cgit v1.2.3