module RailsEnvPrompt

Constants

VERSION

Public Class Methods

app_name() click to toggle source
# File lib/rails_env_prompt.rb, line 6
def self.app_name
  @app_name ||= begin
    application_class = Rails.application.class

    case
    when application_class.method_defined?(:module_parent_name) then application_class.module_parent_name
    when application_class.method_defined?(:parent_name) then application_class.parent_name
    else application_class.name =~ /::[^:]+\z/ ? -$` : nil
    end
  end
end
colored(text, color) click to toggle source
# File lib/rails_env_prompt.rb, line 42
def self.colored(text, color)
  "\033[00;#{color}m#{text}\033[00m"
end
environment_color() click to toggle source
# File lib/rails_env_prompt.rb, line 46
def self.environment_color
  case Rails.env
  when 'development' then 32 # green
  when 'staging' then 33 # yellow
  else 31 # red
  end
end
parse(string) click to toggle source
# File lib/rails_env_prompt.rb, line 26
def self.parse(string)
  string.gsub('[APP]', app_name)
        .gsub('[ENV]', colored(Rails.env, environment_color))
        .gsub('[TENANT]', defined?(Apartment) ? Apartment::Tenant.current : '')
end
template() click to toggle source
# File lib/rails_env_prompt.rb, line 18
def self.template
  [
    '[APP]',
    '[ENV]',
    tenant_prompt
  ].compact.join('/')
end
tenant_prompt() click to toggle source
# File lib/rails_env_prompt.rb, line 36
def self.tenant_prompt
  return unless defined?(Apartment)

  '[TENANT]'
end
to_s() click to toggle source
# File lib/rails_env_prompt.rb, line 32
def self.to_s
  parse(template)
end