Sha256: 11bc781bd4e5e70a80ab7e1ff71076b883c90e2c9d585f10689dee894a7ebfe6

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

# Assembles tool environment variables into a single string or array
module Reviewer
  class Tool
    class Env
      attr_reader :env_pairs

      def initialize(env_pairs)
        @env_pairs = env_pairs
      end

      def to_s
        to_a.compact.join(' ')
      end

      def to_a
        env = []
        env_pairs.each { |key, value| env << env(key, value) }
        env
      end


      private

      def env(key, value)
        return nil if key.to_s.blank? || value.to_s.blank?

        value = needs_quotes?(value) ? "'#{value}'" : value

        "#{key.to_s.strip.upcase}=#{value.to_s.strip};"
      end

      def needs_quotes?(value)
        value.is_a?(String) && value.include?(' ')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reviewer-0.1.1 lib/reviewer/tool/env.rb