Module: DockerCore::Process
- Defined in:
- lib/docker_core.rb
Class Method Summary collapse
- .capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false) ⇒ Object
- .command(*arguments, sudo: SUDO) ⇒ Object
- .execute(*arguments, sudo: SUDO, echo: true) ⇒ Object
- .invoke(title, delegate, *arguments) ⇒ Object
- .run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true) ⇒ Object
- .wait(second = 0) ⇒ Object
Class Method Details
.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/docker_core.rb', line 356 def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false) begin command = self.command(*arguments, sudo: sudo) if echo Color.echo(": #{command}", Color::YELLOW) end data = `#{command}` result = strip ? "#{data}".strip : data self.wait(wait) return result rescue raise unless throw return '' end end |
.command(*arguments, sudo: SUDO) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/docker_core.rb', line 338 def self.command(*arguments, sudo: SUDO) if true == sudo arguments.unshift('sudo') end if sudo.is_a?(String) && false == "#{sudo}".empty? arguments.unshift('su-exec', sudo) end return Paser.arguments(*arguments).join(' ') end |
.execute(*arguments, sudo: SUDO, echo: true) ⇒ Object
393 394 395 396 397 398 399 400 401 |
# File 'lib/docker_core.rb', line 393 def self.execute(*arguments, sudo: SUDO, echo: true) command = self.command(*arguments, sudo: sudo) if echo Color.echo("= #{command}", Color::CYAN) end exec(command) end |
.invoke(title, delegate, *arguments) ⇒ Object
406 407 408 409 410 411 |
# File 'lib/docker_core.rb', line 406 def self.invoke(title, delegate, *arguments) color = Color::YELLOW Color.echo("> #{title}", color) delegate.call(*arguments) Color.echo("< #{title}", color) end |
.run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/docker_core.rb', line 379 def self.run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true) command = self.command(*arguments, sudo: sudo) if echo Color.echo("+ #{command}", Color::GREEN) end result = system(command, exception: throw) self.wait(wait) return result end |
.wait(second = 0) ⇒ Object
325 326 327 328 329 330 331 332 333 334 |
# File 'lib/docker_core.rb', line 325 def self.wait(second = 0) if second.is_a?(Numeric) if 0 > second return sleep end if 0 < second return sleep(second) end end end |