Sha256: 2fe383aeb588a3e7a7cfdb41e2f76292d36914a15bcd5f0c7f63a57341c74959

Contents?: true

Size: 893 Bytes

Versions: 7

Compression:

Stored size: 893 Bytes

Contents

require 'socket'

module TerraformDevKit
  class Environment
    attr_reader :name

    def initialize(name)
      /^[0-9a-zA-Z]+$/ =~ name || (raise "Invalid environment name: #{name}")
      @name = name.downcase
    end

    def config
      case @name
      when 'prod'
        'prod'
      when 'test'
        'test'
      else
        'dev'
      end
    end

    def local_backend?
      case @name
      when 'prod', 'test'
        false
      else
        true
      end
    end

    def working_dir
      File.join(ROOT_PATH, 'envs', @name)
    end

    def self.temp_name
      hostname = Socket.gethostname
      date = Time.now.strftime('%y%m%d%H%M')
      env = "#{hostname}#{date}"
      env.gsub(/[^0-9a-zA-Z]/, '')
    end

    def self.running_on_jenkins?
      ENV.key?('JENKINS_URL') && ENV.key?('BUILD_ID')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
TerraformDevKit-0.3.3 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.2 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.1 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.3.1.pre.rc1 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.2.7 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.2.6 lib/TerraformDevKit/environment.rb
TerraformDevKit-0.2.5 lib/TerraformDevKit/environment.rb