require "rails/generators" require "rails/generators/rails/app/app_generator" require "jobshop/version" module Jobshop class AppBuilder < Rails::AppBuilder def readme template "README.md.tt" end def procfile template "Procfile" end def gemfile super append_to_file "Gemfile", <<~GEMFILE \ngem "jobshop", "~> #{Jobshop.gem_version}" GEMFILE end def config_schema_format return if options[:pretend] data = "config.active_record.schema_format = :sql" sentinel = /class [a-z_:]+ < Rails::Application/i inject_into_file("config/application.rb", "\n #{data}", after: sentinel, verbose: true) end def mount_engine return if options[:pretend] route %Q(mount Jobshop::Engine => "/") end end module Generators class AppGenerator < Rails::Generators::AppGenerator def self.source_root File.expand_path("templates", __dir__) end def self.source_paths [ Rails::Generators::AppGenerator.source_root, Jobshop::Generators::AppGenerator.source_root ] end hide! class_option :help, type: :boolean, aliases: "-h", group: :other, desc: "Show this help message and quit" class_option :version, type: :boolean, aliases: "-v", group: :other, desc: "Show Jobshop version number and quit" def initialize(*args) super config = args.last.is_a?(Hash) ? args.pop : { } jobshop_options = config[:jobshop_options] || { } self.options = options.merge(jobshop_options).freeze end def create_root_files super build :procfile end def remove_session_store_initializer_until_rails_5_1 remove_file "config/initializers/session_store.rb" end def finish_template generate "jobshop:config" unless options[:pretend] build :config_schema_format build :mount_engine super end def run_bundle super bundle_command("binstub jobshop") if bundle_install? end protected def get_builder_class Jobshop::AppBuilder end end end end