Sha256: 21321d0f84210ffa43d795e7aeddce4248ad37bc0f4c4d44d894e2e1b7a15f3e

Contents?: true

Size: 870 Bytes

Versions: 2

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

require 'json'
require 'net/http'
require 'uri'

module  Chamber
module  Adapters
module  Cloud
class   Heroku
  attr_accessor :app

  def initialize(options = {})
    self.app = options.fetch(:app)
  end

  def add_environment_variable(name, value)
    value = value.shellescape unless value =~ /\n/

    response = heroku(%Q{config:set #{name}="#{value}"})

    fail NameError, "The variable name '#{name}' is invalid" if response.match?(/invalid/)

    response
  end

  def environment_variables
    @environment_variables ||= ::JSON.parse(heroku('config --json'))
  end

  def remove_environment_variable(name)
    heroku("config:unset #{name}")
  end

  private

  def heroku(command)
    Bundler.with_clean_env { `heroku #{command}#{app_option} 2>&1` }
  end

  def app_option
    app ? " --app='#{app}'" : ''
  end
end
end
end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chamber-2.13.1 lib/chamber/adapters/cloud/heroku.rb
chamber-2.13.0 lib/chamber/adapters/cloud/heroku.rb