Sha256: 2990815122d793dfff1b79cef20460870802db8d0262fa9f210473b653a6b78e

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Karafka
  # Karafka framework Cli
  class Cli < Thor
    # Install Karafka Cli action
    class Install < Base
      desc 'Install all required things for Karafka application in current directory'

      # Directories created by default
      INSTALL_DIRS = %w[
        app/models
        app/controllers
        app/responders
        app/workers
        config
        log
        tmp/pids
      ].freeze

      # Where should we map proper files from templates
      INSTALL_FILES_MAP = {
        'karafka.rb.example' => Karafka.boot_file.basename,
        'sidekiq.yml.example' => 'config/sidekiq.yml.example',
        'application_worker.rb.example' => 'app/workers/application_worker.rb',
        'application_controller.rb.example' => 'app/controllers/application_controller.rb',
        'application_responder.rb.example' => 'app/responders/application_responder.rb'
      }.freeze

      # Install all required things for Karafka application in current directory
      def call
        INSTALL_DIRS.each do |dir|
          FileUtils.mkdir_p Karafka.root.join(dir)
        end

        INSTALL_FILES_MAP.each do |source, target|
          target = Karafka.root.join(target)
          next if File.exist?(target)

          source = Karafka.core_root.join("templates/#{source}")
          FileUtils.cp_r(source, target)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
karafka-0.6.0.rc2 lib/karafka/cli/install.rb