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.11.18 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.17 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.16 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.15 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.14 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.12 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.11 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.9 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.8 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.7 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.6 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.5 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.4 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.3 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.2 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.1 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.11.0 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.9 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.8 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.10.7 lib/fedux_org_stdlib/rake/shell_task.rb