class Gem::Tasks::Console

The `console` task.

Constants

DEFAULT_COMMAND

The default command to run

DEFAULT_CONSOLE

The default Interactive Ruby Console

Attributes

command[RW]

The Ruby Console command

options[RW]

Additional options for the Ruby Console

Public Class Methods

new(options={}) { |self| ... } click to toggle source

Initializes the `console` task.

@param [Hash] options

Additional options.

@option options [String] :command (DEFAULT_COMMAND)

The Ruby Console command to run.

@option options [Array] :options

Additional options for the Ruby Console.
Calls superclass method
# File lib/rubygems/tasks/console.rb, line 34
def initialize(options={})
  super()

  @command = options.fetch(:command,DEFAULT_COMMAND)
  @options = Array(options[:options])

  yield self if block_given?
  define
end

Public Instance Methods

console(name=nil) click to toggle source

Builds the complete arguments for the console command.

@param [Symbol, String] name

The name of the gemspec to load.

@return [Array<String>]

The arguments for the console command.

@api semipublic

# File lib/rubygems/tasks/console.rb, line 69
def console(name=nil)
  gemspec = @project.gemspec(name)

  require_paths = gemspec.require_paths
  require_file  = gemspec.name.gsub('-',File::SEPARATOR)

  arguments = [@command]

  # add -I options for lib/ or ext/ directories
  arguments.push(*require_paths.map { |dir| "-I#{dir}" })

  # add a -rrubygems to explicitly load rubygems on Ruby 1.8
  arguments.push('-rrubygems') if RUBY_VERSION < '1.9'

  # add an -r option to require the library
  arguments.push('-r' + require_file)

  # push on additional options
  arguments.push(*@options)

  if @project.bundler?
    # run under `bundle exec`
    arguments.unshift('bundle', 'exec')
  end

  return run(*arguments)
end
define() click to toggle source

Defines the `console` task.

# File lib/rubygems/tasks/console.rb, line 47
def define
  @project.gemspecs.each_key do |name|
    namespace :console do
      task(name) { console(name) }
    end
  end

  desc "Spawns an Interactive Ruby Console"
  task :console => "console:#{@project.primary_gemspec}"
end