Class: WhatsAppNotifier::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- WhatsAppNotifier::Generators::InstallGenerator
- Defined in:
- lib/generators/whatsapp_notifier/install_generator.rb
Instance Method Summary collapse
- #create_initializer ⇒ Object
- #ensure_gitignore_entries ⇒ Object
- #ensure_procfile_entry ⇒ Object
- #next_steps ⇒ Object
- #run_doctor ⇒ Object
Instance Method Details
#create_initializer ⇒ Object
9 10 11 12 13 |
# File 'lib/generators/whatsapp_notifier/install_generator.rb', line 9 def create_initializer return if File.exist?("config/initializers/whatsapp_notifier.rb") template "whatsapp_notifier.rb", "config/initializers/whatsapp_notifier.rb" end |
#ensure_gitignore_entries ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/whatsapp_notifier/install_generator.rb', line 30 def ensure_gitignore_entries entries = [ "# WhatsApp Notifier", "/tmp/whatsapp_notifier", "/whatsapp_service/node_modules", "/whatsapp_service/.wwebjs_cache", "/whatsapp_service/.wwebjs_auth" ] content = File.exist?(".gitignore") ? File.read(".gitignore") : "" missing = entries.reject { |entry| content.include?(entry) } return if missing.empty? append_to_file(".gitignore", "\n#{missing.join("\n")}\n") end |
#ensure_procfile_entry ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/generators/whatsapp_notifier/install_generator.rb', line 15 def ensure_procfile_entry procfile = "Procfile.dev" line = "whatsapp: bundle exec whatsapp_notifier service" unless File.exist?(procfile) create_file(procfile, "#{line}\n") return end content = File.read(procfile) return if content.lines.any? { |existing| existing.strip == line } append_to_file(procfile, "\n#{line}\n") end |
#next_steps ⇒ Object
54 55 56 57 |
# File 'lib/generators/whatsapp_notifier/install_generator.rb', line 54 def next_steps say("\nSetup complete.", :green) say("Run `bin/dev`, open `/dashboard/whatsapp/qr`, then send a test message.", :green) end |
#run_doctor ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/generators/whatsapp_notifier/install_generator.rb', line 46 def run_doctor say("\nRunning setup doctor...", :yellow) ok = WhatsAppNotifier::Doctor.run(io: $stdout, app_root: destination_root) return if ok raise Thor::Error, "Setup checks failed. Fix items above, then run `bundle exec whatsapp_notifier doctor`." end |