class HerokuConfig::Config
Public Class Methods
new(app)
click to toggle source
# File lib/heroku_config/config.rb, line 5 def initialize(app) @app = app check_heroku_cli_installed! end
Public Instance Methods
get(name)
click to toggle source
# File lib/heroku_config/config.rb, line 10 def get(name) return "fakevalue" if ENV['HEROKU_CONFIG_TEST'] out = sh "heroku config:get #{name} -a #{@app}" return out if !out&.empty? end
set(*params)
click to toggle source
# File lib/heroku_config/config.rb, line 16 def set(*params) case params.size when 1 # Hash set_many(params.first) when 2 # 2 Strings set_one(name, value) else raise "ERROR: #{params.class} is a class that is not supported" end end
set_many(hash)
click to toggle source
Example:
set(a: 1, b: 2) => heroku config:set a=1 b=2 -a APP
# File lib/heroku_config/config.rb, line 37 def set_many(hash) args = hash.map { |k,v| "#{k}=#{v}" }.join(' ') sh "heroku config:set #{args} -a #{@app}", include_stderr: true end
set_one(name, value)
click to toggle source
# File lib/heroku_config/config.rb, line 27 def set_one(name, value) sh "heroku config:set #{name} #{value} -a #{@app}" end
Private Instance Methods
check_heroku_cli_installed!()
click to toggle source
# File lib/heroku_config/config.rb, line 62 def check_heroku_cli_installed! return if heroku_cli_installed? puts "The heroku cli is not installed. Please install the heroku cli: https://devcenter.heroku.com/articles/heroku-cli" exit 1 end
heroku_cli_installed?()
click to toggle source
# File lib/heroku_config/config.rb, line 69 def heroku_cli_installed? system("type heroku > /dev/null 2>&1") end
sh(command, include_stderr: false)
click to toggle source
# File lib/heroku_config/config.rb, line 43 def sh(command, include_stderr: false) puts "=> #{command}" stdout, stderr, status = Open3.capture3(command) out = stdout.strip unless status.success? puts "ERROR: #{stderr}".color(:red) if stderr.empty? puts "STDOUT: #{stdout}" end exit 1 end if include_stderr stderr + "\n" + out else out end end