Class: Front::CLI::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/front/cli/script.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Script

Returns a new instance of Script.



4
5
6
7
# File 'lib/front/cli/script.rb', line 4

def initialize(path)
  @commands = []
  @path = path
end

Instance Method Details

#enqueue(cmd) ⇒ Object



9
10
11
# File 'lib/front/cli/script.rb', line 9

def enqueue(cmd)
  @commands << cmd
end

#pending?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/front/cli/script.rb', line 33

def pending?
  @commands.length > 0
end

#runObject



25
26
27
28
29
30
31
# File 'lib/front/cli/script.rb', line 25

def run
  if pending?
    save()
    pid = Kernel.spawn(@path)
    Process.detach pid
  end
end

#saveObject



13
14
15
16
17
18
19
20
21
22
23
# 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