Class: Gitlab::QA::Docker::Command
- Inherits:
-
Object
- Object
- Gitlab::QA::Docker::Command
- Defined in:
- lib/gitlab/qa/docker/command.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#stream_output ⇒ Object
readonly
Returns the value of attribute stream_output.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(*args) ⇒ Object
- #==(other) ⇒ Object
- #env(name, value) ⇒ Object
- #execute!(&block) ⇒ Object
-
#initialize(cmd = nil, mask_secrets: nil, stream_output: false) ⇒ Command
constructor
Shell command.
-
#mask_secrets ⇒ String
Returns a masked string form of a Command.
- #name(identity) ⇒ Object
- #port(mapping) ⇒ Object
- #to_s ⇒ Object
- #volume(from, to, opt = :z) ⇒ Object
Constructor Details
#initialize(cmd = nil, mask_secrets: nil, stream_output: false) ⇒ Command
Shell command
14 15 16 17 18 |
# File 'lib/gitlab/qa/docker/command.rb', line 14 def initialize(cmd = nil, mask_secrets: nil, stream_output: false) @args = Array(cmd) @mask_secrets = Array(mask_secrets) @stream_output = stream_output end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/gitlab/qa/docker/command.rb', line 7 def args @args end |
#stream_output ⇒ Object (readonly)
Returns the value of attribute stream_output.
7 8 9 |
# File 'lib/gitlab/qa/docker/command.rb', line 7 def stream_output @stream_output end |
Class Method Details
.execute(cmd, mask_secrets: nil, &block) ⇒ Object
67 68 69 |
# File 'lib/gitlab/qa/docker/command.rb', line 67 def self.execute(cmd, mask_secrets: nil, &block) new(cmd, mask_secrets: mask_secrets).execute!(&block) end |
Instance Method Details
#<<(*args) ⇒ Object
20 21 22 |
# File 'lib/gitlab/qa/docker/command.rb', line 20 def <<(*args) tap { @args.concat(args) } end |
#==(other) ⇒ Object
55 56 57 |
# File 'lib/gitlab/qa/docker/command.rb', line 55 def ==(other) to_s == other.to_s end |
#env(name, value) ⇒ Object
32 33 34 |
# File 'lib/gitlab/qa/docker/command.rb', line 32 def env(name, value) tap { @args.push(%(--env #{name}="#{value}")) } end |
#execute!(&block) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/gitlab/qa/docker/command.rb', line 59 def execute!(&block) Docker::Shellout.new(self).execute!(&block) rescue Docker::Shellout::StatusError => e e.set_backtrace([]) raise e end |
#mask_secrets ⇒ String
Returns a masked string form of a Command
51 52 53 |
# File 'lib/gitlab/qa/docker/command.rb', line 51 def mask_secrets @mask_secrets.each_with_object(+to_s) { |secret, s| s.gsub!(secret, '*****') } end |
#name(identity) ⇒ Object
28 29 30 |
# File 'lib/gitlab/qa/docker/command.rb', line 28 def name(identity) tap { @args.push("--name #{identity}") } end |
#port(mapping) ⇒ Object
36 37 38 |
# File 'lib/gitlab/qa/docker/command.rb', line 36 def port(mapping) tap { @args.push("-p #{mapping}") } end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/gitlab/qa/docker/command.rb', line 40 def to_s "docker #{@args.join(' ')}" end |
#volume(from, to, opt = :z) ⇒ Object
24 25 26 |
# File 'lib/gitlab/qa/docker/command.rb', line 24 def volume(from, to, opt = :z) tap { @args.push("--volume #{from}:#{to}:#{opt}") } end |