Module: DockerCore::Process

Defined in:
lib/docker_core.rb

Class Method Summary collapse

Class Method Details

.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false) ⇒ Object

Parameters:

  • (defaults to: SUDO)
  • (defaults to: false)
  • (defaults to: 0)
  • (defaults to: true)
  • (defaults to: false)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/docker_core.rb', line 208

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

Parameters:

  • (defaults to: SUDO)


190
191
192
193
194
195
196
197
198
199
200
# File 'lib/docker_core.rb', line 190

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

Parameters:

  • (defaults to: SUDO)


245
246
247
248
249
250
251
252
253
# File 'lib/docker_core.rb', line 245

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

Parameters:



258
259
260
261
262
263
# File 'lib/docker_core.rb', line 258

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

Parameters:

  • (defaults to: SUDO)
  • (defaults to: true)
  • (defaults to: 0)
  • (defaults to: true)


231
232
233
234
235
236
237
238
239
240
241
# File 'lib/docker_core.rb', line 231

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

Parameters:

  • (defaults to: 0)


177
178
179
180
181
182
183
184
185
186
# File 'lib/docker_core.rb', line 177

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