class PoBoxGenerator < Rails::Generators::NamedBase source_root File.expand_path("templates", __dir__) def setup_initializer create_file "config/initializers/po_box.rb", "PoBox.emailable_class = \"#{name.camelize}\"" end def mount_engine route "mount PoBox::Engine, at: \"/po_box\"" end def include_concerns inject_into_file "app/models/#{name.tableize.singularize}.rb", after: "class #{name.camelize} < ApplicationRecord\n" do <<-RUBY include PoBox::Emailable RUBY end end def setup_inbox inject_into_file "app/mailboxes/application_mailbox.rb", after: "class ApplicationMailbox < ActionMailbox::Base\n" do <<-RUBY routing all: "po_box/inbox" RUBY end end def append_to_manifest append_to_file "app/assets/config/manifest.js" do "//= link po_box/application.css\n" end end end