Class: Front::CLI::Script
- Inherits:
-
Object
- Object
- Front::CLI::Script
- Defined in:
- lib/front/cli/script.rb
Instance Method Summary collapse
- #enqueue(cmd) ⇒ Object
-
#initialize(path) ⇒ Script
constructor
A new instance of Script.
- #pending? ⇒ Boolean
- #run ⇒ Object
- #save ⇒ Object
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
33 34 35 |
# File 'lib/front/cli/script.rb', line 33 def pending? @commands.length > 0 end |
#run ⇒ Object
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 |
#save ⇒ Object
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 |