Class: Rundoc::CodeCommand::BashRunner::Cd

Inherits:
Rundoc::CodeCommand::BashRunner show all
Defined in:
lib/rundoc/code_command/bash/cd.rb

Instance Attribute Summary

Attributes inherited from Rundoc::CodeCommand::BashRunner

#contents, #io

Instance Method Summary collapse

Methods inherited from Rundoc::CodeCommand::BashRunner

#raise_on_error?, #sanitize_escape_chars, #shell, #to_md

Constructor Details

#initialize(line, io: $stdout) ⇒ Cd

Returns a new instance of Cd.



5
6
7
8
# File 'lib/rundoc/code_command/bash/cd.rb', line 5

def initialize(line, io: $stdout)
  @io = io
  @line = line
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/rundoc/code_command/bash/cd.rb', line 18

def call(env)
  line = @line.sub("cd", "").strip
  @io.puts "running $ cd #{line}"

  suppress_chdir_warning do
    Dir.chdir(line)
  end

  nil
end

#suppress_chdir_warningObject



10
11
12
13
14
15
16
# File 'lib/rundoc/code_command/bash/cd.rb', line 10

def suppress_chdir_warning
  old_verbose = $VERBOSE
  $VERBOSE = nil
  yield
ensure
  $VERBOSE = old_verbose
end