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:

  • arguments (Array)
  • sudo (Boolean, String) (defaults to: SUDO)
  • throw (Boolean) (defaults to: false)
  • wait (Numeric) (defaults to: 0)
  • strip (Boolean) (defaults to: true)
  • echo (Boolean) (defaults to: false)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/docker_core.rb', line 137

def self.capture(*arguments, sudo: SUDO, throw: false, wait: 0, strip: true, echo: false)
  begin
    command = self.command(*arguments, substitute: 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:

  • arguments (Array)
  • sudo (Boolean, String) (defaults to: SUDO)


119
120
121
122
123
124
125
126
127
128
129
# File 'lib/docker_core.rb', line 119

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:

  • arguments (Array)
  • sudo (Boolean, String) (defaults to: SUDO)


174
175
176
177
178
179
180
181
182
# File 'lib/docker_core.rb', line 174

def self.execute(*arguments, sudo: SUDO, echo: true)
  command = self.command(*arguments, substitute: sudo)

  if echo
    Color.echo("= #{command}", Color::CYAN)
  end

  exec(command)
end

.invoke(title, delegate, *arguments) ⇒ Object

Parameters:

  • title (String)
  • delegate (Method)
  • arguments (Array)


187
188
189
190
191
192
# File 'lib/docker_core.rb', line 187

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:

  • arguments (Array)
  • sudo (Boolean, String) (defaults to: SUDO)
  • throw (Boolean) (defaults to: true)
  • wait (Numeric) (defaults to: 0)
  • echo (Boolean) (defaults to: true)


160
161
162
163
164
165
166
167
168
169
170
# File 'lib/docker_core.rb', line 160

def self.run(*arguments, sudo: SUDO, throw: true, wait: 0, echo: true)
  command = self.command(*arguments, substitute: 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:

  • second (Numeric) (defaults to: 0)


106
107
108
109
110
111
112
113
114
115
# File 'lib/docker_core.rb', line 106

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