Sha256: 22e78ff3940648269c912a2e24f5c046c949e39925576585bebb4b2259683e9c

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

require "rails/generators"
require_relative "../actions"

module Suspenders
  class JobsGenerator < Rails::Generators::Base
    include Suspenders::Actions

    source_root(
      File.expand_path(
        File.join("..", "..", "..", "templates"),
        File.dirname(__FILE__),
      ),
    )

    def add_jobs_gem
      gem "delayed_job_active_record"
      Bundler.with_clean_env { run "bundle install" }
    end

    def configure_background_jobs_for_rspec
      generate "delayed_job:active_record"
    end

    def initialize_active_job
      copy_file(
        "active_job.rb",
        "config/initializers/active_job.rb",
      )
    end

    def configure_active_job
      configure_application_file(
        "config.active_job.queue_adapter = :delayed_job",
      )
      configure_environment "test", "config.active_job.queue_adapter = :inline"
    end

    private

    def configure_application_file(config)
      inject_into_file(
        "config/application.rb",
        "\n    #{config}",
        before: "\n  end",
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
suspenders-1.50.0 lib/suspenders/generators/jobs_generator.rb
suspenders-1.49.0 lib/suspenders/generators/jobs_generator.rb
suspenders-1.48.0 lib/suspenders/generators/jobs_generator.rb
suspenders-1.47.0 lib/suspenders/generators/jobs_generator.rb