Module: Haiti::CommandLineHelpers

Extended by:
CommandLineHelpers
Included in:
CommandLineHelpers
Defined in:
lib/haiti/command_line_helpers.rb

Defined Under Namespace

Classes: Invocation

Instance Method Summary collapse

Instance Method Details

#configObject



59
60
61
# File 'lib/haiti/command_line_helpers.rb', line 59

def config
  Haiti.config
end

#execute(command, stdin_data, env_vars) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/haiti/command_line_helpers.rb', line 23

def execute(command, stdin_data, env_vars)
  stdin_data ||= ''
  env_vars   ||= {}
  in_proving_grounds do
    with_bin_in_path do
      Invocation.new *Open3.capture3(env_vars, command, stdin_data: stdin_data)
    end
  end
end

#in_proving_grounds(&block) ⇒ Object



37
38
39
# File 'lib/haiti/command_line_helpers.rb', line 37

def in_proving_grounds(&block)
  Dir.chdir config.proving_grounds_dir, &block
end

#make_proving_groundsObject



41
42
43
# File 'lib/haiti/command_line_helpers.rb', line 41

def make_proving_grounds
  FileUtils.mkdir_p config.proving_grounds_dir
end

#path_to(filename) ⇒ Object



45
46
47
# File 'lib/haiti/command_line_helpers.rb', line 45

def path_to(filename)
  in_proving_grounds { File.join config.proving_grounds_dir, filename }
end

#read_file(filename) ⇒ Object



33
34
35
# File 'lib/haiti/command_line_helpers.rb', line 33

def read_file(filename)
  in_proving_grounds { File.read filename }
end

#with_bin_in_pathObject

workaround for Ruby 2.0 bug where passing the new path as the first arg wasn’t working bug report submitted here: bugs.ruby-lang.org/issues/8004



51
52
53
54
55
56
57
# File 'lib/haiti/command_line_helpers.rb', line 51

def with_bin_in_path
  original_path = ENV['PATH']
  ENV['PATH'] = "#{config.bin_dir}:#{ENV['PATH']}"
  yield
ensure
  ENV['PATH'] = original_path
end

#write_file(filename, body) ⇒ Object



16
17
18
19
20
21
# File 'lib/haiti/command_line_helpers.rb', line 16

def write_file(filename, body)
  in_proving_grounds do
    FileUtils.mkdir_p File.dirname filename
    File.open(filename, 'w') { |file| file.write body }
  end
end