Class: Sunabamail::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/sunabamail/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_mount_routesObject



30
31
32
33
34
35
36
37
# File 'lib/generators/sunabamail/install_generator.rb', line 30

def add_mount_routes
  route <<~ROUTE
    if Rails.configuration.action_mailer.delivery_method == :sunabamail
      mount Sunabamail::Engine => "/sunabamail"
    end

  ROUTE
end

#configure_adapterObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/sunabamail/install_generator.rb', line 10

def configure_adapter
  pathname = Pathname(destination_root).join("config/environments/development.rb")

  if File.read(pathname).match?(/config\.action_mailer\.delivery_method\s*=/)
    gsub_file pathname,
      /(# )?config\.action_mailer\.delivery_method\s+=.*\n/,
      "config.action_mailer.delivery_method = :sunabamail\n"
  else
    environment <<~RUBY, env: "development"
      config.action_mailer.delivery_method = :sunabamail
    RUBY
  end
end

#configure_databaseObject



24
25
26
27
28
# File 'lib/generators/sunabamail/install_generator.rb', line 24

def configure_database
  environment <<~RUBY, env: "development"
    config.sunabamail.connects_to = { database: { writing: :sunabamail } }
  RUBY
end

#copy_filesObject



6
7
8
# File 'lib/generators/sunabamail/install_generator.rb', line 6

def copy_files
  template "db/sunabamail_schema.rb"
end

#database_configuration_hintObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/sunabamail/install_generator.rb', line 39

def database_configuration_hint
  say ""
  say "#{set_color('', :green)} Sunabamail setup complete"
  say ""

  say "Changes applied:", :blue
  say
  say "  • Updated config/environments/development.rb"
  say "    - action_mailer.delivery_method = :sunabamail"
  say "    - config.sunabamail.connects_to = { database: { writing: :sunabamail } }"
  say "  • Updated config/routes.rb"
  say "    - Mounted Sunabamail::Engine at /sunabamail (when delivery_method is :sunabamail)"
  say ""

  say "Next steps:", :blue
  say

  say "1. Update config/database.yml:", :bold
  say ""
  say "    # if you're SQLite, it'll look like this:"
  say ""
  say "    development:"
  say "      primary:"
  say "        <<: *default"
  say "        database: storage/development.sqlite3"
  say "      sunabamail:"
  say "        <<: *default"
  say "        database: storage/development_sunabamail.sqlite3"
  say "        migrations_paths: db/sunabamail_migrate"
  say ""
  say "    # ...or if you're using MySQL/PostgreSQL/Trilogy:"
  say ""
  say "    development:"
  say "      primary: &primary_development"
  say "        <<: *default"
  say "        database: app_development"
  say "        username: app"
  say "        password: <%= ENV[\"APP_DATABASE_PASSWORD\"] %>"
  say "      sunabamail:"
  say "        <<: *primary_development"
  say "        database: app_development_sunabamail"
  say "        migrations_paths: db/sunabamail_migrate"
  say ""
  say "2. Run:"
  say ""
  say "    $ rails db:prepare"
  say ""
end