class Rookie::Tasks::Console

This task provides an easy way to interactively test your gem by automatically loading and requiring it in an interactive ruby session.

Attributes

command[W]

The full command to execute.

program[RW]

The name of the program to invoke.

spec[RW]

The gem specification.

Public Class Methods

new(spec, opts = {}) { |self| ... } click to toggle source

Creates a new console task with the given parameters. Options may specify:

:program

the name of the program to invoke; irb by default.

:command

the full command to execute. Use if the command you want to run doesn't take the -I and -r command line arguments.

Yields the instance if given a block.

Tasks do not get defined automatically; don't forget to call define_tasks!

# File lib/rookie/tasks/console.rb, line 37
def initialize(spec, opts = {})
  self.spec = spec
  self.program = opts.fetch :program, :irb
  self.command = opts.fetch :command, nil
  yield self if block_given?
end

Public Instance Methods

command() click to toggle source

Unless set explicitly, will be automatically generated from the program name and gem specification.

# File lib/rookie/tasks/console.rb, line 21
def command
  @command ||= generate_command_string
end
define_tasks!() click to toggle source

Defines the console task.

# File lib/rookie/tasks/console.rb, line 45
def define_tasks!
  desc 'Starts an interactive ruby session with the gem loaded'
  task :console do
    sh command
  end
end
generate_command_string() click to toggle source

Generates a command string from this task's program name and gem specification. For example:

irb -I lib -r gem_name
# File lib/rookie/tasks/console.rb, line 56
def generate_command_string
  program.to_s.dup.tap do |command_string|
    spec.require_paths.each do |path|
      command_string << ' -I ' << path
    end
    command_string << ' -r ' << spec.name
  end
end