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
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/docker_core.rb', line 320 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
302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/docker_core.rb', line 302 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
357 358 359 360 361 362 363 364 365 |
# File 'lib/docker_core.rb', line 357 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
370 371 372 373 374 375 |
# File 'lib/docker_core.rb', line 370 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
343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/docker_core.rb', line 343 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
289 290 291 292 293 294 295 296 297 298 |
# File 'lib/docker_core.rb', line 289 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 |