123456789_123456789_123456789_123456789_123456789_

Class: Rails::Console

Relationships & Source Files
Namespace Children
Modules:
Inherits: Object
Defined in: railties/lib/rails/commands/console/console_command.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(app, options = {}) ⇒ Console

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 21

def initialize(app, options = {})
  @app     = app
  @options = options

  app.sandbox = sandbox?

  if sandbox? && app.config.disable_sandbox
    puts "Error: Unable to start console in sandbox mode as sandbox mode is disabled (config.disable_sandbox is true)."
    exit 1
  end

  app.load_console

  @console = app.config.console || begin
    require "irb"
    require "irb/completion"

    IRB::WorkSpace.prepend(BacktraceCleaner)

    if !Rails.env.local?
      ENV["IRB_USE_AUTOCOMPLETE"] ||= "false"
    end

    IRB
  end
end

Class Method Details

.start(*args)

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 15

def self.start(*args)
  new(*args).start
end

Instance Attribute Details

#app (readonly)

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 19

attr_reader :options, :app, :console

#console (readonly)

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 19

attr_reader :options, :app, :console

#environment (readonly) Also known as: #environment?

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 56

def environment
  options[:environment]
end

#environment? (readonly)

Alias for #environment.

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 59

alias_method :environment?, :environment

#options (readonly)

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 19

attr_reader :options, :app, :console

#sandbox?Boolean (readonly)

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 48

def sandbox?
  return options[:sandbox] if !options[:sandbox].nil?

  return false if Rails.env.local?

  app.config.sandbox_by_default
end

Instance Method Details

#set_environment!

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 61

def set_environment!
  Rails.env = environment
end

#start

[ GitHub ]

  
# File 'railties/lib/rails/commands/console/console_command.rb', line 65

def start
  set_environment! if environment?

  if sandbox?
    puts "Loading #{Rails.env} environment in sandbox (Rails #{Rails.version})"
    puts "Any modifications you make will be rolled back on exit"
  else
    puts "Loading #{Rails.env} environment (Rails #{Rails.version})"
  end

  if defined?(console::ExtendCommandBundle)
    console::ExtendCommandBundle.include(Rails::ConsoleMethods)
  end
  console.start
end