diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-02-10 17:36:11 -0500 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-02-22 20:46:06 -0500 |
commit | 83921b8f87495d5edb66f67549f0c169d2ea3e73 (patch) | |
tree | a68ca13b282561b64c96579b08b380f4938ade40 /actioncable/lib | |
parent | 1813b29fc7632959800252f36e4b2e6ed4ac7266 (diff) | |
download | rails-83921b8f87495d5edb66f67549f0c169d2ea3e73.tar.gz rails-83921b8f87495d5edb66f67549f0c169d2ea3e73.tar.bz2 rails-83921b8f87495d5edb66f67549f0c169d2ea3e73.zip |
Generate ApplicationCable files if they do not already exist
Diffstat (limited to 'actioncable/lib')
3 files changed, 26 insertions, 0 deletions
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 |