Sha256: 6db29561e73484cb98ebc6627d08e89c040113b6fb3ac2232fca3d74dc93b16f

Contents?: true

Size: 1.4 KB

Versions: 7

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 and gemfile_exists?
        cmd << command

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

      private

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.7.21 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.7.20 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.7.19 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.7.18 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.7.17 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.7.16 lib/fedux_org_stdlib/rake/shell_task.rb
fedux_org-stdlib-0.7.15 lib/fedux_org_stdlib/rake/shell_task.rb