Sha256: 390488218e67aae32bbe7dcb57574baf71cd00e9fd1e1d1c2457f3288b799d00

Contents?: true

Size: 1.4 KB

Versions: 56

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8
require 'fedux_org_stdlib/require_files'
require 'fedux_org_stdlib/rake/task'
require 'fedux_org_stdlib/require_files'
require_library %w(erubis)

module FeduxOrgStdlib
  module Rake
    # Shell Task
    #
    # @see Rakefile
    class ShellTask < Task
      # @!attribute [r] command
      #   The command to be executed
      attr_reader :command

      # @!attribute [r] use_bundler
      #   Use bundler to run command
      attr_reader :use_bundler

      # Create a new shell task
      #
      # @param [String] command
      #   The command to be executed
      #
      # @param [true,false] use_bundler
      #   Should the command be prefixed with `bundle exec`
      #
      # @see Task
      #   For other arguments accepted
      def initialize(
        command:,
        use_bundler: false,
        **args
      )
        super(**args)

        @use_bundler = use_bundler
        @command     = command
      end

      # @private
      def run_task(_verbose)
        logger.warn 'Gemfile does not exist. Running bundler will fail. I am going to run the command without `bundle exec`.' unless gemfile_exists?

        cmd = []
        cmd << 'bundle exec' if use_bundler && gemfile_exists?
        cmd << command

        sh Erubis::Eruby.new(cmd.join(' ')).result(instance_binding)
      end

      private

      def gemfile_exists?
        !Dir.glob('Gemfile').blank?
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.10.6 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.5 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.4 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.3 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.2 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.1 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.0 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.8 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.7 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.6 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.5 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.4 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.2 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.1 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.9.0 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.8.11 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.8.10 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.8.9 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.8.8 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.8.7 lib/fedux_org_stdlib/rake/shell_task.rb