From 83921b8f87495d5edb66f67549f0c169d2ea3e73 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Wed, 10 Feb 2016 17:36:11 -0500 Subject: Generate ApplicationCable files if they do not already exist --- .../lib/rails/generators/channel/channel_generator.rb | 16 ++++++++++++++++ .../channel/templates/application_cable/channel.rb | 5 +++++ .../channel/templates/application_cable/connection.rb | 5 +++++ 3 files changed, 26 insertions(+) create mode 100644 actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb create mode 100644 actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb (limited to 'actioncable/lib/rails/generators') diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb index c5d398810a..c98b4ed829 100644 --- a/actioncable/lib/rails/generators/channel/channel_generator.rb +++ b/actioncable/lib/rails/generators/channel/channel_generator.rb @@ -15,12 +15,28 @@ module Rails if options[:assets] template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee") end + + generate_application_cable_files end protected def file_name @_file_name ||= super.gsub(/\_channel/i, '') end + + def generate_application_cable_files + return if self.behavior != :invoke + + files = [ + 'application_cable/channel.rb', + 'application_cable/connection.rb' + ] + + files.each do |name| + path = File.join('app/channels/', name) + template(name, path) if !File.exist?(path) + end + end end end end diff --git a/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb b/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb new file mode 100644 index 0000000000..d56fa30f4d --- /dev/null +++ b/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb b/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb new file mode 100644 index 0000000000..b4f41389ad --- /dev/null +++ b/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end -- cgit v1.2.3 From cf423f8f767895d608284acb3543f7c9ba15ccf4 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Wed, 10 Feb 2016 18:10:02 -0500 Subject: Add notes for future selves Once RubyGems 2.5.0 is required, then the duplicated files can be removed, and symlinks can be used instead. [ci skip] --- actioncable/lib/rails/generators/channel/channel_generator.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actioncable/lib/rails/generators') diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb index c98b4ed829..6debe40c91 100644 --- a/actioncable/lib/rails/generators/channel/channel_generator.rb +++ b/actioncable/lib/rails/generators/channel/channel_generator.rb @@ -24,6 +24,7 @@ module Rails @_file_name ||= super.gsub(/\_channel/i, '') end + # FIXME: Change these files to symlinks once RubyGems 2.5.0 is required. def generate_application_cable_files return if self.behavior != :invoke -- cgit v1.2.3