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
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/docker_core.rb', line 355 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
337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/docker_core.rb', line 337 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
392 393 394 395 396 397 398 399 400 |
# File 'lib/docker_core.rb', line 392 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
405 406 407 408 409 410 |
# File 'lib/docker_core.rb', line 405 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
378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/docker_core.rb', line 378 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
324 325 326 327 328 329 330 331 332 333 |
# File 'lib/docker_core.rb', line 324 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 |