Class: PolylingoChat::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- PolylingoChat::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/polylingo_chat/install/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_routes ⇒ Object
- #configure_cable ⇒ Object
- #copy_migrations ⇒ Object
- #create_channels ⇒ Object
- #create_initializer ⇒ Object
- #create_javascript_files ⇒ Object
- #create_models ⇒ Object
- #download_actioncable ⇒ Object
- #setup_solid_cable ⇒ Object
- #show_readme ⇒ Object
- #update_application_js ⇒ Object
- #update_importmap ⇒ Object
Class Method Details
.next_migration_number(dirname) ⇒ Object
13 14 15 16 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 13 def self.next_migration_number(dirname) next_migration_number = current_migration_number(dirname) + 1 ActiveRecord::Migration.next_migration_number(next_migration_number) end |
Instance Method Details
#add_routes ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 63 def add_routes route 'mount ActionCable.server => "/cable"' route " resources :conversations do\n resources :messages, only: [:create]\n end\n RUBY\nend\n" |
#configure_cable ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 44 def configure_cable if File.exist?("config/cable.yml") gsub_file "config/cable.yml", /^development:\s*\n\s+adapter:\s+\w+.*$/m do |match| "development:\n adapter: solid_cable\n polling_interval: 0.1.seconds\n message_retention: 1.day" end end end |
#copy_migrations ⇒ Object
18 19 20 21 22 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 18 def copy_migrations migration_template "create_conversations.rb", "db/migrate/create_conversations.rb" migration_template "create_participants.rb", "db/migrate/create_participants.rb" migration_template "create_messages.rb", "db/migrate/create_messages.rb" end |
#create_channels ⇒ Object
30 31 32 33 34 35 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 30 def create_channels empty_directory "app/channels/application_cable" template "channels/application_cable/channel.rb", "app/channels/application_cable/channel.rb" template "channels/application_cable/connection.rb", "app/channels/application_cable/connection.rb" template "channels/polylingo_chat_channel.rb", "app/channels/polylingo_chat_channel.rb" end |
#create_initializer ⇒ Object
98 99 100 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 98 def create_initializer template "initializer.rb", "config/initializers/polylingo_chat.rb" end |
#create_javascript_files ⇒ Object
37 38 39 40 41 42 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 37 def create_javascript_files empty_directory "app/javascript/channels" template "javascript/chat.js", "app/javascript/chat.js" template "javascript/channels/consumer.js", "app/javascript/channels/consumer.js" template "javascript/channels/index.js", "app/javascript/channels/index.js" end |
#create_models ⇒ Object
24 25 26 27 28 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 24 def create_models template "models/conversation.rb", "app/models/conversation.rb" template "models/participant.rb", "app/models/participant.rb" template "models/message.rb", "app/models/message.rb" end |
#download_actioncable ⇒ Object
57 58 59 60 61 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 57 def download_actioncable empty_directory "vendor/javascript" say "Downloading ActionCable ESM module...", :green run "curl -o vendor/javascript/@rails--actioncable.js https://ga.jspm.io/npm:@rails/[email protected]/app/assets/javascripts/actioncable.esm.js" end |
#setup_solid_cable ⇒ Object
52 53 54 55 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 52 def setup_solid_cable say "Setting up Solid Cable...", :green rails_command "solid_cable:install", abort_on_failure: false end |
#show_readme ⇒ Object
102 103 104 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 102 def show_readme readme "README" if behavior == :invoke end |
#update_application_js ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 86 def update_application_js if File.exist?("app/javascript/application.js") append_to_file "app/javascript/application.js" do "\n // PolylingoChat real-time chat\n import \"chat\"\n JS\n end\n end\nend\n" |
#update_importmap ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/generators/polylingo_chat/install/install_generator.rb', line 72 def update_importmap if File.exist?("config/importmap.rb") append_to_file "config/importmap.rb" do "\n # PolylingoChat real-time chat\n pin \"@rails/actioncable\", to: \"@rails--actioncable.js\"\n pin_all_from \"app/javascript/channels\", under: \"channels\"\n pin \"chat\", to: \"chat.js\"\n RUBY\n end\n end\nend\n" |