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
The full command to execute.
The name of the program to invoke.
The gem specification.
Public Class Methods
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
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
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
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