class Front::CLI::Script

Public Class Methods

new(path) click to toggle source
# File lib/front/cli/script.rb, line 4
def initialize(path)
  @commands = []
  @path = path
end

Public Instance Methods

enqueue(cmd) click to toggle source
# File lib/front/cli/script.rb, line 9
def enqueue(cmd)
  @commands << cmd
end
pending?() click to toggle source
# File lib/front/cli/script.rb, line 33
def pending?
  @commands.length > 0
end
run() click to toggle source
# File lib/front/cli/script.rb, line 25
def run
  if pending?
    save()
    pid = Kernel.spawn(@path)
    Process.detach pid
  end
end
save() click to toggle source
# File lib/front/cli/script.rb, line 13
def save
  File.open(@path, 'w') do |file|
    file.puts("#!/bin/bash")

    @commands.each do |command|
      file.puts(command)
    end
  end

  File.chmod(0755, @path)
end