Class: Ogam::Execute

Inherits:
Object
  • Object
show all
Defined in:
lib/ogam/execute.rb

Overview

Methods to execute GAM commands

Class Method Summary collapse

Class Method Details

.csv_command(csv_path, command, pretend: true) ⇒ Object



31
32
33
# File 'lib/ogam/execute.rb', line 31

def self.csv_command(csv_path, command, pretend: true)
  single("gam csv #{Shellwords.escape(csv_path)} #{command.strip}", pretend: pretend)
end

.fetch(command, pretend: true) ⇒ Object



17
18
19
20
21
22
# File 'lib/ogam/execute.rb', line 17

def self.fetch(command, pretend: true)
  puts "#{pretend ? "[PRETEND] " : nil}Fetching results from #{command}"
  return if pretend

  `~/bin/gam/#{command.strip}`
end

.fetch_csv(command, pretend: true) ⇒ Object



24
25
26
27
28
29
# File 'lib/ogam/execute.rb', line 24

def self.fetch_csv(command, pretend: true)
  result = fetch(command, pretend: pretend)
  return unless result

  CSV.parse(result, headers: true)
end

.multiple(commands, pretend: true) ⇒ Object

rubocop:disable Metrics/MethodLength



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ogam/execute.rb', line 36

def self.multiple(commands, pretend: true)
  return if commands.empty?

  puts "#{pretend ? "[PRETEND] " : nil}Executing multiple commands:"
  commands.each do |command|
    puts "\t#{command}"
  end
  return if pretend

  f = Tempfile.new
  commands.each { |command| f.puts command.strip }
  f.close
  single("gam batch #{f.path}", pretend: pretend)
  f.unlink
end

.single(command, pretend: true) ⇒ Object



10
11
12
13
14
15
# File 'lib/ogam/execute.rb', line 10

def self.single(command, pretend: true)
  puts "#{pretend ? "[PRETEND] " : nil}Executing #{command}"
  return if pretend

  system("~/bin/gam/#{command.strip}", exception: true)
end