<commit_before>require "heroku/helpers"

module Heroku::Helpers::HerokuPostgresql

  extend self

  def app_config_vars
    @app_config_vars ||= api.get_config_vars(app).body
  end

  def hpg_addon_name
    ENV['HEROKU_POSTGRESQL_ADDON_NAME'] || 'heroku-postgresql'
  end

  def hpg_addon_prefix
    ENV["HEROKU_POSTGRESQL_ADDON_PREFIX"] || "HEROKU_POSTGRESQL"
  end

  def hpg_databases
    @hpg_databases ||= app_config_vars.inject({}) do |hash, (name, url)|
      if name =~ /^(#{hpg_addon_prefix}\w+)_URL$/
        hash.update($1 => url)
      end
      hash
    end
  end

  def hpg_resolve(name, default=nil)
    if app_config_vars["DATABASE_URL"]
      hpg_databases["DATABASE"] = app_config_vars["DATABASE_URL"]
    end
    if hpg_databases.empty?
      error("Your app has no databases.")
    end

    name = name.to_s.upcase.gsub(/_URL$/, "")

    if hpg_databases[name]
      [hpg_pretty_name(name), hpg_databases[name]]
    elsif default && name.empty? && app_config_vars[default]
      [hpg_pretty_name(default), app_config_vars[default]]
    elsif name.empty?
      error("Unknown database. Valid options are: #{hpg_databases.keys.sort.join(", ")}")
    else
      error("Unknown database: #{name}. Valid options are: #{hpg_databases.keys.sort.join(", ")}")
    end
  end
<commit_msg>allow pg stuff to be referred to by color shorthand<commit_after>require "heroku/helpers"

module Heroku::Helpers::HerokuPostgresql

  extend self

  def app_config_vars
    @app_config_vars ||= api.get_config_vars(app).body
  end

  def hpg_addon_name
    ENV['HEROKU_POSTGRESQL_ADDON_NAME'] || 'heroku-postgresql'
  end

  def hpg_addon_prefix
    ENV["HEROKU_POSTGRESQL_ADDON_PREFIX"] || "HEROKU_POSTGRESQL"
  end

  def hpg_databases
    @hpg_databases ||= app_config_vars.inject({}) do |hash, (name, url)|
      if name =~ /^(#{hpg_addon_prefix}\w+)_URL$/
        hash.update($1 => url)
      end
      hash
    end
  end

  def hpg_resolve(name, default=nil)
    if app_config_vars["DATABASE_URL"]
      hpg_databases["DATABASE"] = app_config_vars["DATABASE_URL"]
    end
    if hpg_databases.empty?
      error("Your app has no databases.")
    end

    name = name.to_s.upcase.gsub(/_URL$/, "")

    if hpg_databases[name]
      [hpg_pretty_name(name), hpg_databases[name]]
    elsif (config_var = "HEROKU_POSTGRESQL_#{name}") && hpg_databases[config_var]
      [hpg_pretty_name(config_var), hpg_databases[config_var]]
    elsif default && name.empty? && app_config_vars[default]
      [hpg_pretty_name(default), app_config_vars[default]]
    elsif name.empty?
      error("Unknown database. Valid options are: #{hpg_databases.keys.sort.join(", ")}")
    else
      error("Unknown database: #{name}. Valid options are: #{hpg_databases.keys.sort.join(", ")}")
    end
  end

{'fraction_non_alphanumeric': 0.12846347607052896, 'fraction_numerical': 0.0007196833393306944, 'mean_word_length': 3.793103448275862, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3616275', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1025, 'n_words': 183}