module Heroku

Public Class Methods

review_app?() click to toggle source
# File lib/heroku/stage.rb, line 16
def review_app?
  !ENV['HEROKU_PARENT_APP_NAME'].nil?
end
stage() click to toggle source

Returns the current Heroku stage.

Heroku.stage # => "staging"
Heroku.stage.staging? # => true
Heroku.stage.production? # => false
# File lib/heroku/stage.rb, line 12
def stage
  @_stage ||= ActiveSupport::StringInquirer.new(heroku_pipeline_stage)
end

Private Class Methods

enable_dyno_metadata_message(exception) click to toggle source
# File lib/heroku/stage.rb, line 31
    def enable_dyno_metadata_message(exception)
      <<-USAGE
#{exception.message}

Remember to enable the heroku dyno metadata to add the HEROKU_APP_NAME key to the environment.
To do that run the folowing command:

  heroku labs:enable runtime-dyno-metadata --remote production

On the next deploy the key will be populated with the app name
      USAGE
    end
heroku_pipeline_stage() click to toggle source
# File lib/heroku/stage.rb, line 22
def heroku_pipeline_stage
  return ENV.fetch('HEROKU_APP_NAME')[/pr-(\d*)/] if review_app?

  dev_or_test = Rails.env.development? || Rails.env.test?
  dev_or_test ? '' : ENV.fetch('HEROKU_APP_NAME')[/staging|production/]
rescue KeyError
  raise $!, enable_dyno_metadata_message($!), $!.backtrace
end