Sha256: 989758d9d844e7dc28d4fdb1d4ebc10e8008f715ded49bcf64cb0100e1b726ec

Contents?: true

Size: 718 Bytes

Versions: 1

Compression:

Stored size: 718 Bytes

Contents

module Rundock
  module Operation
    class Command < Base
      def run(backend, attributes = {})
        @instruction.each do |i|
          if i.is_a?(Hash)
            attributes.merge!(i)
            next
          end

          logging(i, 'info')

          backend.run_commands(
            assign_args(i, attributes[:task_args]), attributes
          )
        end
      end

      private

      def assign_args(cmd, args)
        return cmd unless args
        cmd.gsub(/\$#/, args.length.to_s)
           .gsub(/\$@/, args.join(' '))
           .gsub(/\$[1-9]/) { |arg_n| args[arg_n.chars[1..-1].join.to_i - 1] }
           .gsub(/(\$\{)(\w+)(\})/) { ENV[Regexp.last_match(2)] }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rundock-1.1.0 lib/rundock/operation/command.rb