Sha256: 3a9b7d2ed2b37d9e55528b2789b4117a713fd1e4051595315df2f6e07eac4300

Contents?: true

Size: 1.64 KB

Versions: 4

Compression:

Stored size: 1.64 KB

Contents

# encoding: utf-8

require 'thor'

module Daiku
  class Plugins
    class Sidekiq
      class CLI < ::Thor::Group
        include ::Thor::Actions
        argument :app

        def self.source_root
          File.expand_path('../', __FILE__)
        end

        def bootrb
          insert_into_file "#{app}/lib/boot.rb", "require File.join($app_root, 'config/sidekiq')\n", after: "# jobs\n"
        end

        def config
          template('_templates/sidekiq.rb.tt', "#{app}/config/sidekiq.rb")
          empty_directory("#{app}/lib/jobs")
          create_file("#{app}/lib/jobs/.gitkeep", "")
        end

        def dotenv
          append_to_file "#{app}/.env", "SIDEKIQ_USERNAME=#{app}\n"
          append_to_file "#{app}/.env", "SIDEKIQ_PASSWORD=#{app}\n"
        end

        def gemfile
          insert_into_file "#{app}/Gemfile", "gem 'sidekiq'\n", after: "gem 'puma', require: false\n"
        end

        def procfile
          append_to_file "#{app}/Procfile", "sidekiq: bundle exec sidekiq -q default -r ./lib/boot.rb\n"
        end

        def rackup
          content = <<-SKMW.strip_heredoc
            require 'sidekiq/web'
            map '/sidekiq' do
              Sidekiq::Web.use Rack::Auth::Basic do |username, password|
                username == ENV['SIDEKIQ_USERNAME'] && password == ENV['SIDEKIQ_PASSWORD']
              end
              run Sidekiq::Web\n
            end
          SKMW
          append_to_file "#{app}/config.ru", content
        end

        def spechelper
          insert_into_file "#{app}/spec/spec_helper.rb", "require 'sidekiq/testing'\n", before: "require 'minitest/autorun'\n"
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
daiku-0.2.2 lib/daiku/plugins/sidekiq/cli.rb
daiku-0.2.1 lib/daiku/plugins/sidekiq/cli.rb
daiku-0.2.0 lib/daiku/plugins/sidekiq/cli.rb
daiku-0.1.1 lib/daiku/plugins/sidekiq/cli.rb