Class: Jive::Shell
- Inherits:
-
Object
- Object
- Jive::Shell
- Defined in:
- lib/jive/shell.rb
Constant Summary collapse
- COMMAND_MAP =
{ cd: "/usr/bin/cd", echo: "/usr/bin/echo", git: "/usr/bin/git", mkdir: "/bin/mkdir" }.freeze
Instance Method Summary collapse
- #after_run(tasks) ⇒ Object
- #execute(command, env: {}) ⇒ Object
- #expand(command) ⇒ Object
- #run_each(tasks) ⇒ Object
- #run_safely ⇒ Object
Instance Method Details
#after_run(tasks) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/jive/shell.rb', line 22 def after_run(tasks) finalizer_fd = 42 pipe = IO.new(finalizer_fd) pipe.puts(tasks.map { |x| x.join(":") }.join("\n")) rescue Errno::EBADF => e puts e exit 1 end |
#execute(command, env: {}) ⇒ Object
18 19 20 |
# File 'lib/jive/shell.rb', line 18 def execute(command, env: {}) system(env, (command)) end |
#expand(command) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/jive/shell.rb', line 31 def (command) Array(command) .flatten .map { |x| COMMAND_MAP.fetch(x, x).to_s } .join(" ") end |
#run_each(tasks) ⇒ Object
12 13 14 15 16 |
# File 'lib/jive/shell.rb', line 12 def run_each(tasks) tasks.each do |task| break unless execute(task) end end |
#run_safely ⇒ Object
38 39 40 41 42 43 |
# File 'lib/jive/shell.rb', line 38 def run_safely yield rescue StandardError => e puts e after_run([%w[noop noop]]) end |