Class: Rvim::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/rvim/filter.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.failed_statusObject



22
23
24
# File 'lib/rvim/filter.rb', line 22

def self.failed_status
  Struct.new(:success?, :exitstatus).new(false, 1)
end

.run(cmd, input: '', shell: '/bin/sh', shellcmdflag: '-c') ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rvim/filter.rb', line 13

def self.run(cmd, input: '', shell: '/bin/sh', shellcmdflag: '-c')
  sh = shell.to_s.empty? ? '/bin/sh' : shell
  flag = shellcmdflag.to_s.empty? ? '-c' : shellcmdflag
  out, err, status = Open3.capture3(sh, flag, cmd.to_s, stdin_data: input.to_s)
  Result.new(stdout: out, stderr: err, status: status)
rescue => e
  Result.new(stdout: '', stderr: e.message, status: failed_status)
end