Module: SaferRailsConsole

Defined in:
lib/safer_rails_console.rb,
lib/safer_rails_console/colors.rb,
lib/safer_rails_console/console.rb,
lib/safer_rails_console/railtie.rb,
lib/safer_rails_console/version.rb,
lib/safer_rails_console/rails_version.rb,
lib/safer_rails_console/patches/railtie/sandbox.rb,
lib/safer_rails_console/patches/sandbox/auto_rollback.rb,
lib/safer_rails_console/patches/sandbox/transaction_read_only.rb

Defined Under Namespace

Modules: Colors, Console, Patches, RailsVersion Classes: Configuration, Railtie

Constant Summary collapse

VERSION =
'0.11.0'

Class Method Summary collapse

Class Method Details

.configObject



56
57
58
# File 'lib/safer_rails_console.rb', line 56

def config
  @config ||= Configuration.new
end

.environment_nameObject



12
13
14
15
16
17
18
19
20
# File 'lib/safer_rails_console.rb', line 12

def environment_name
  if ENV.key?('SAFER_RAILS_CONSOLE_ENVIRONMENT_NAME')
    ENV['SAFER_RAILS_CONSOLE_ENVIRONMENT_NAME']
  elsif config.environment_names.key?(::Rails.env.downcase)
    config.environment_names[::Rails.env.downcase]
  else
    'unknown env'
  end
end

.prompt_colorObject



22
23
24
25
26
27
28
29
30
# File 'lib/safer_rails_console.rb', line 22

def prompt_color
  if ENV.key?('SAFER_RAILS_CONSOLE_PROMPT_COLOR')
    SaferRailsConsole::Colors.const_get(ENV['SAFER_RAILS_CONSOLE_PROMPT_COLOR'].upcase)
  elsif config.environment_prompt_colors.key?(::Rails.env.downcase)
    config.environment_prompt_colors[::Rails.env.downcase]
  else
    SaferRailsConsole::Colors::NONE
  end
end

.sandbox_environment?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/safer_rails_console.rb', line 32

def sandbox_environment?
  if ENV.key?('SAFER_RAILS_CONSOLE_SANDBOX_ENVIRONMENT')
    ActiveModel::Type::Boolean.new.cast(ENV['SAFER_RAILS_CONSOLE_SANDBOX_ENVIRONMENT'])
  else
    config.sandbox_environments.include?(::Rails.env.downcase)
  end
end

.warn_environment?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/safer_rails_console.rb', line 40

def warn_environment?
  if ENV.key?('SAFER_RAILS_CONSOLE_WARN_ENVIRONMENT')
    ActiveModel::Type::Boolean.new.cast(ENV['SAFER_RAILS_CONSOLE_WARN_ENVIRONMENT'])
  else
    config.warn_environments.include?(::Rails.env.downcase)
  end
end

.warn_textObject



48
49
50
51
52
53
54
# File 'lib/safer_rails_console.rb', line 48

def warn_text
  if ENV.key?('SAFER_RAILS_CONSOLE_WARN_TEXT')
    ENV['SAFER_RAILS_CONSOLE_WARN_TEXT']
  else
    config.warn_text
  end
end