Class: Rookie::Tasks::Console

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/rookie/tasks/console.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, opts = {}) {|_self| ... } ⇒ Console

Returns a new instance of Console.

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
20
# File 'lib/rookie/tasks/console.rb', line 14

def initialize(spec, opts = {})
  self.spec = spec
  self.program = opts.fetch :program, 'irb'
  self.command = opts.fetch :command, nil
  yield self if block_given?
  define
end

Instance Attribute Details

#commandObject



10
11
12
# File 'lib/rookie/tasks/console.rb', line 10

def command
  @command ||= generate_command_string
end

#programObject

Returns the value of attribute program.



7
8
9
# File 'lib/rookie/tasks/console.rb', line 7

def program
  @program
end

#specObject

Returns the value of attribute spec.



7
8
9
# File 'lib/rookie/tasks/console.rb', line 7

def spec
  @spec
end

Instance Method Details

#defineObject



22
23
24
25
26
27
# File 'lib/rookie/tasks/console.rb', line 22

def define
  desc 'Starts an interactive ruby session with your gem loaded'
  task :console do
    sh command
  end
end

#generate_command_stringObject



29
30
31
32
33
34
35
36
# File 'lib/rookie/tasks/console.rb', line 29

def generate_command_string
  program.dup.tap do |command_string|
    spec.require_paths.each do |path|
      command_string << ' -I ' << path
    end
    command_string << ' -r ' << spec.name
  end
end