Sha256: 1a0a4507a541a91a471f87cb425eddfb4b7eaea973452df024d8034bc9a469a5

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

require 'taketo/constructs/base_construct'
require 'shellwords'

module Taketo
  module Constructs

    class Command < BaseConstruct
      include Shellwords

      attr_accessor :command, :description

      def self.default
        new(:default).tap { |cmd| cmd.command = "bash" }
      end

      def self.explicit_command(command_string)
        new(:explicit_command).tap { |cmd| cmd.command = command_string.to_s }
      end

      def render(server, options = {})
        %Q[#{location(server, options)} #{environment_variables(server)} #{command}].strip.squeeze(" ")
      end

      def to_s
        command.to_s
      end

      private

      def location(server, options = {})
        directory = options.fetch(:directory) { server.default_location }
        %Q[cd #{shellescape directory};] if directory
      end

      def environment_variables(server)
        server.environment_variables.map { |k, v| %Q[#{k}=#{shellescape v}] }.join(" ")
      end
    end

  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
taketo-0.2.0 lib/taketo/constructs/command.rb