docker_core 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/docker_core.rb +40 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e24b7a9fd2ff938ceda59f6846768c1e414dd54b9b99ee22d8384a3044d1978
4
- data.tar.gz: 4b15e835e7b275c3b8dbbb5e82db512870a07d551f3064f7f0ce2a8e9606e625
3
+ metadata.gz: 80affaf62801f9396342f5e34a9b4d7d9c60cbb7734eb072c53fd639a0128795
4
+ data.tar.gz: fb93776e06070bcf7633f4307d0c2fb16e0c1c447c1548dd57618319c61dd7aa
5
5
  SHA512:
6
- metadata.gz: 4b35e8577e6893fd84518b7eeaa8bb364684b3d632806b1c33ad0a884a3ac3457e2dbbc3c5697355a1785722f11f0b8d6076d62185b5d56a0c0f8438bbf6201d
7
- data.tar.gz: 2b73c1c304b64e38ffb065c948a5856753c7b33100b436816f9da02219ca1f6c73931b1db2b021ac40044572085e1f5b38a537c781555ff868ddbe7b3e0302c0
6
+ metadata.gz: 357c0774652360108f2a5cc9773b482999a3f454b0af977ab609b80618fbe8a2157af83d8bc1041afa1e0056f2aa7e7b61ec2f5fa60b56a7caff996296b07d8e
7
+ data.tar.gz: 861b83b14df2c399f64a5a580dc61281414c0c581528118d38cbcdd044e09c79387fb334930c170b0197b3bd7f6c84a2739efb064112f60011131d26d034e926
data/lib/docker_core.rb CHANGED
@@ -56,15 +56,20 @@ module DockerCore
56
56
 
57
57
  if hash.is_a?(Hash)
58
58
  hash.each do |key, value|
59
- name = '--' + self.kebab(key)
59
+ short = 1 == key.length
60
+ prefix = short ? '-' : '--'
61
+ separator = short ? ' ' : '='
62
+ name = prefix + self.kebab(key)
60
63
 
61
64
  if true == value
62
65
  items << name
63
66
  next
64
67
  end
65
68
 
66
- value = "#{value}".gsub(/\\/, '\&\&').gsub('"', '\"')
67
- items << %(#{name}="#{value}")
69
+ [value].flatten.each do |item|
70
+ item = "#{item}".gsub(/\\/, '\&\&').gsub('"', '\"')
71
+ items << %(#{name}#{separator}"#{item}")
72
+ end
68
73
  next
69
74
  end
70
75
  end
@@ -96,22 +101,39 @@ module DockerCore
96
101
  end
97
102
 
98
103
  module Process
104
+ # @param [Numeric] duration
105
+ def self.wait(duration = 0)
106
+ if duration.is_a?(Numeric)
107
+ if 0 > duration
108
+ return sleep
109
+ end
110
+ if 0 < duration
111
+ return sleep(duration)
112
+ end
113
+ end
114
+ end
115
+
99
116
  # @param [Array] arguments
100
- # @param [Boolean] substitute
117
+ # @param [Boolean, String] substitute
101
118
  def self.command(*arguments, substitute: false)
102
- if substitute
103
- arguments.unshift('su-exec', USER)
119
+ if true == substitute
120
+ arguments.unshift('sudo')
121
+ end
122
+
123
+ if substitute.is_a?(String) && false == "#{substitute}".empty?
124
+ arguments.unshift('su-exec', substitute)
104
125
  end
105
126
 
106
127
  return Paser.arguments(*arguments).join(' ')
107
128
  end
108
129
 
109
130
  # @param [Array] arguments
110
- # @param [Boolean] substitute
131
+ # @param [Boolean, String] substitute
111
132
  # @param [Boolean] exception
133
+ # @param [Numeric] duration
112
134
  # @param [Boolean] strip
113
135
  # @param [Boolean] verbose
114
- def self.capture(*arguments, substitute: false, exception: false, strip: true, verbose: false)
136
+ def self.capture(*arguments, substitute: false, exception: false, duration: 0, strip: true, verbose: false)
115
137
  begin
116
138
  command = self.command(*arguments, substitute: substitute)
117
139
 
@@ -120,7 +142,9 @@ module DockerCore
120
142
  end
121
143
 
122
144
  data = `#{command}`
123
- return strip ? "#{data}".strip : data
145
+ result = strip ? "#{data}".strip : data
146
+ self.wait(duration)
147
+ return result
124
148
  rescue
125
149
  raise unless exception
126
150
  return ''
@@ -128,16 +152,19 @@ module DockerCore
128
152
  end
129
153
 
130
154
  # @param [Array] arguments
131
- # @param [Boolean] substitute
155
+ # @param [Boolean, String] substitute
132
156
  # @param [Boolean] exception
133
- def self.run(*arguments, substitute: false, exception: true)
157
+ # @param [Numeric] duration
158
+ def self.run(*arguments, substitute: false, exception: true, duration: 0)
134
159
  command = self.command(*arguments, substitute: substitute)
135
160
  Color.echo("+ #{command}", Color::GREEN)
136
- return system(command, exception: exception)
161
+ result = system(command, exception: exception)
162
+ self.wait(duration)
163
+ return result
137
164
  end
138
165
 
139
166
  # @param [Array] arguments
140
- # @param [Boolean] substitute
167
+ # @param [Boolean, String] substitute
141
168
  def self.execute(*arguments, substitute: false)
142
169
  command = self.command(*arguments, substitute: substitute)
143
170
  Color.echo("= #{command}", Color::CYAN)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - agrozyme
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2021-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fileutils