class Promptify::Railtie

Private Instance Methods

app_name() click to toggle source
# File lib/promptify/railtie.rb, line 31
def app_name
  # ActiveSupport's `Module#parent_name` is deprecated in 6.1+.
  if Rails.application.class.respond_to?(:module_parent_name)
    Rails.application.class.module_parent_name.underscore.dasherize
  else
    Rails.application.class.parent_name.underscore.dasherize
  end
end
environment() click to toggle source
# File lib/promptify/railtie.rb, line 53
def environment
  # Distinguish "preview" apps from production/staging apps.
  if Rails.application.config.try(:preview_app)
    Pry::Helpers::Text.yellow("PREVIEW")
  elsif Rails.env.staging?
    Pry::Helpers::Text.yellow(Rails.env.upcase)
  elsif Rails.env.production?
    Pry::Helpers::Text.red(Rails.env.upcase)
  elsif Rails.env.development?
    # "DEVELOPMENT" was too long to always display locally.
    Pry::Helpers::Text.white("DEV")
  else
    # Test, etc.
    Pry::Helpers::Text.white(Rails.env.upcase)
  end
end
heroku_app() click to toggle source
# File lib/promptify/railtie.rb, line 40
def heroku_app
  return unless ENV["HEROKU_APP_NAME"]

  "[#{Pry::Helpers::Text.cyan(ENV['HEROKU_APP_NAME'])}]"
end
new_prompt() click to toggle source
# File lib/promptify/railtie.rb, line 46
def new_prompt
  [
    proc { |*a| "[#{app_name}]#{heroku_app}[#{environment}]> " },
    proc { |*a| "[#{app_name}]#{heroku_app}[#{environment}]> " },
  ]
end
show_pretty_prompt() click to toggle source
# File lib/promptify/railtie.rb, line 15
def show_pretty_prompt
  old_prompt = Pry.config.prompt

  if Pry::VERSION >= "0.13.0"
    return Pry::Prompt[:promptify] if Pry::Prompt[:promptify]

    Pry.prompt = Pry::Prompt.new(
      :promptify,
      "Simple Rails console enhancements",
      new_prompt,
    )
  else
    Pry.config.prompt = new_prompt
  end
end