Class: Rookie::Tasks::Console
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Rookie::Tasks::Console
- Defined in:
- lib/rookie/tasks/console.rb
Overview
This task provides an easy way to interactively test your gem by automatically loading and requiring it in an interactive ruby session.
Instance Attribute Summary collapse
-
#command ⇒ Object
Unless set explicitly, will be automatically generated from the #program name and gem specification.
-
#program ⇒ Object
The name of the program to invoke.
-
#spec ⇒ Object
The gem specification.
Instance Method Summary collapse
-
#define_tasks! ⇒ Object
Defines the console task.
-
#generate_command_string ⇒ Object
Generates a command string from this task’s #program name and gem specification.
-
#initialize(spec, opts = {}) {|_self| ... } ⇒ Console
constructor
Creates a new console task with the given parameters.
Constructor Details
#initialize(spec, opts = {}) {|_self| ... } ⇒ Console
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!
37 38 39 40 41 42 |
# 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 |
Instance Attribute Details
#command ⇒ Object
Unless set explicitly, will be automatically generated from the #program name and gem specification.
21 22 23 |
# File 'lib/rookie/tasks/console.rb', line 21 def command @command ||= generate_command_string end |
#program ⇒ Object
The name of the program to invoke.
14 15 16 |
# File 'lib/rookie/tasks/console.rb', line 14 def program @program end |
#spec ⇒ Object
The gem specification.
11 12 13 |
# File 'lib/rookie/tasks/console.rb', line 11 def spec @spec end |
Instance Method Details
#define_tasks! ⇒ Object
Defines the console task.
45 46 47 48 49 50 |
# 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 ⇒ Object
Generates a command string from this task’s #program name and gem specification. For example:
irb -I lib -r gem_name
56 57 58 59 60 61 62 63 |
# 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 |