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
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/docker_core.rb', line 251 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
233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/docker_core.rb', line 233 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
288 289 290 291 292 293 294 295 296 |
# File 'lib/docker_core.rb', line 288 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
301 302 303 304 305 306 |
# File 'lib/docker_core.rb', line 301 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
274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/docker_core.rb', line 274 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
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/docker_core.rb', line 220 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 |