pdk 2.7.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/README.md +2 -48
  4. data/lib/pdk/analytics/client/google_analytics.rb +22 -26
  5. data/lib/pdk/analytics/util.rb +0 -1
  6. data/lib/pdk/analytics.rb +1 -1
  7. data/lib/pdk/bolt.rb +1 -0
  8. data/lib/pdk/cli/build.rb +53 -56
  9. data/lib/pdk/cli/bundle.rb +34 -33
  10. data/lib/pdk/cli/console.rb +136 -134
  11. data/lib/pdk/cli/convert.rb +39 -41
  12. data/lib/pdk/cli/env.rb +49 -47
  13. data/lib/pdk/cli/errors.rb +1 -2
  14. data/lib/pdk/cli/exec/command.rb +23 -29
  15. data/lib/pdk/cli/exec/interactive_command.rb +7 -12
  16. data/lib/pdk/cli/exec.rb +4 -11
  17. data/lib/pdk/cli/exec_group.rb +3 -2
  18. data/lib/pdk/cli/get/config.rb +21 -19
  19. data/lib/pdk/cli/get.rb +15 -13
  20. data/lib/pdk/cli/new/class.rb +22 -22
  21. data/lib/pdk/cli/new/defined_type.rb +22 -22
  22. data/lib/pdk/cli/new/fact.rb +19 -19
  23. data/lib/pdk/cli/new/function.rb +20 -20
  24. data/lib/pdk/cli/new/module.rb +40 -38
  25. data/lib/pdk/cli/new/provider.rb +19 -19
  26. data/lib/pdk/cli/new/task.rb +23 -23
  27. data/lib/pdk/cli/new/test.rb +50 -48
  28. data/lib/pdk/cli/new/transport.rb +18 -18
  29. data/lib/pdk/cli/new.rb +11 -9
  30. data/lib/pdk/cli/release/prep.rb +27 -25
  31. data/lib/pdk/cli/release/publish.rb +39 -37
  32. data/lib/pdk/cli/release.rb +152 -149
  33. data/lib/pdk/cli/remove/config.rb +63 -60
  34. data/lib/pdk/cli/remove.rb +15 -13
  35. data/lib/pdk/cli/set/config.rb +91 -89
  36. data/lib/pdk/cli/set.rb +15 -13
  37. data/lib/pdk/cli/test/unit.rb +71 -69
  38. data/lib/pdk/cli/test.rb +9 -7
  39. data/lib/pdk/cli/update.rb +33 -38
  40. data/lib/pdk/cli/util/command_redirector.rb +10 -1
  41. data/lib/pdk/cli/util/interview.rb +11 -4
  42. data/lib/pdk/cli/util/option_normalizer.rb +2 -4
  43. data/lib/pdk/cli/util/option_validator.rb +7 -9
  44. data/lib/pdk/cli/util/update_manager_printer.rb +4 -4
  45. data/lib/pdk/cli/util.rb +32 -48
  46. data/lib/pdk/cli/validate.rb +98 -96
  47. data/lib/pdk/cli.rb +124 -120
  48. data/lib/pdk/config/ini_file.rb +4 -3
  49. data/lib/pdk/config/ini_file_setting.rb +6 -10
  50. data/lib/pdk/config/json.rb +1 -0
  51. data/lib/pdk/config/json_schema_namespace.rb +5 -10
  52. data/lib/pdk/config/json_schema_setting.rb +3 -5
  53. data/lib/pdk/config/json_with_schema.rb +2 -4
  54. data/lib/pdk/config/namespace.rb +19 -13
  55. data/lib/pdk/config/setting.rb +5 -6
  56. data/lib/pdk/config/task_schema.json +116 -0
  57. data/lib/pdk/config/validator.rb +4 -4
  58. data/lib/pdk/config/yaml.rb +3 -8
  59. data/lib/pdk/config/yaml_with_schema.rb +4 -12
  60. data/lib/pdk/config.rb +47 -51
  61. data/lib/pdk/context/control_repo.rb +3 -2
  62. data/lib/pdk/context/module.rb +2 -2
  63. data/lib/pdk/context/none.rb +2 -2
  64. data/lib/pdk/context.rb +4 -5
  65. data/lib/pdk/control_repo.rb +3 -4
  66. data/lib/pdk/generate/defined_type.rb +3 -3
  67. data/lib/pdk/generate/fact.rb +3 -2
  68. data/lib/pdk/generate/function.rb +5 -4
  69. data/lib/pdk/generate/module.rb +91 -106
  70. data/lib/pdk/generate/provider.rb +5 -4
  71. data/lib/pdk/generate/puppet_class.rb +3 -3
  72. data/lib/pdk/generate/puppet_object.rb +9 -12
  73. data/lib/pdk/generate/task.rb +11 -10
  74. data/lib/pdk/generate/transport.rb +8 -7
  75. data/lib/pdk/generate.rb +1 -1
  76. data/lib/pdk/logger.rb +3 -2
  77. data/lib/pdk/module/build.rb +34 -49
  78. data/lib/pdk/module/convert.rb +13 -22
  79. data/lib/pdk/module/metadata.rb +53 -61
  80. data/lib/pdk/module/release.rb +19 -25
  81. data/lib/pdk/module/update.rb +4 -13
  82. data/lib/pdk/module/update_manager.rb +18 -25
  83. data/lib/pdk/module.rb +1 -1
  84. data/lib/pdk/monkey_patches.rb +268 -0
  85. data/lib/pdk/report/event.rb +12 -37
  86. data/lib/pdk/report.rb +4 -4
  87. data/lib/pdk/template/fetcher/git.rb +7 -8
  88. data/lib/pdk/template/fetcher/local.rb +1 -0
  89. data/lib/pdk/template/fetcher.rb +4 -2
  90. data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +4 -9
  91. data/lib/pdk/template/renderer/v1/renderer.rb +19 -20
  92. data/lib/pdk/template/renderer/v1/template_file.rb +4 -8
  93. data/lib/pdk/template/renderer/v1.rb +1 -1
  94. data/lib/pdk/template/renderer.rb +1 -0
  95. data/lib/pdk/template/template_dir.rb +3 -3
  96. data/lib/pdk/template.rb +2 -6
  97. data/lib/pdk/tests/unit.rb +36 -25
  98. data/lib/pdk/util/bundler.rb +10 -14
  99. data/lib/pdk/util/changelog_generator.rb +15 -12
  100. data/lib/pdk/util/env.rb +1 -0
  101. data/lib/pdk/util/filesystem.rb +18 -17
  102. data/lib/pdk/util/git.rb +16 -21
  103. data/lib/pdk/util/json_finder.rb +7 -6
  104. data/lib/pdk/util/puppet_strings.rb +1 -1
  105. data/lib/pdk/util/puppet_version.rb +16 -67
  106. data/lib/pdk/util/ruby_version.rb +9 -13
  107. data/lib/pdk/util/template_uri.rb +17 -29
  108. data/lib/pdk/util/vendored_file.rb +5 -18
  109. data/lib/pdk/util/windows/api_types.rb +70 -64
  110. data/lib/pdk/util/windows/file.rb +31 -27
  111. data/lib/pdk/util/windows/process.rb +59 -61
  112. data/lib/pdk/util/windows/string.rb +19 -12
  113. data/lib/pdk/util.rb +12 -20
  114. data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +1 -1
  115. data/lib/pdk/validate/control_repo/environment_conf_validator.rb +25 -25
  116. data/lib/pdk/validate/external_command_validator.rb +6 -1
  117. data/lib/pdk/validate/internal_ruby_validator.rb +5 -4
  118. data/lib/pdk/validate/invokable_validator.rb +30 -20
  119. data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +12 -14
  120. data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +13 -15
  121. data/lib/pdk/validate/metadata/metadata_validator_group.rb +1 -1
  122. data/lib/pdk/validate/puppet/puppet_epp_validator.rb +16 -18
  123. data/lib/pdk/validate/puppet/puppet_lint_validator.rb +14 -14
  124. data/lib/pdk/validate/puppet/puppet_plan_syntax_validator.rb +1 -1
  125. data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +16 -18
  126. data/lib/pdk/validate/puppet/puppet_validator_group.rb +1 -1
  127. data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +10 -11
  128. data/lib/pdk/validate/ruby/ruby_validator_group.rb +1 -1
  129. data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +19 -24
  130. data/lib/pdk/validate/tasks/tasks_name_validator.rb +11 -13
  131. data/lib/pdk/validate/tasks/tasks_validator_group.rb +1 -1
  132. data/lib/pdk/validate/validator.rb +4 -2
  133. data/lib/pdk/validate/validator_group.rb +6 -3
  134. data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +27 -36
  135. data/lib/pdk/validate/yaml/yaml_validator_group.rb +1 -1
  136. data/lib/pdk/validate.rb +6 -6
  137. data/lib/pdk/version.rb +2 -2
  138. data/lib/pdk.rb +12 -12
  139. metadata +27 -35
  140. data/lib/pdk/cli/config/get.rb +0 -26
  141. data/lib/pdk/cli/config.rb +0 -22
  142. data/lib/pdk/cli/module/build.rb +0 -12
  143. data/lib/pdk/cli/module/generate.rb +0 -47
  144. data/lib/pdk/cli/module.rb +0 -14
@@ -47,9 +47,9 @@ module PDK
47
47
  calculate_diffs
48
48
 
49
49
  {
50
- added: @added_files,
51
- removed: @removed_files.select { |f| PDK::Util::Filesystem.exist?(f) },
52
- modified: @diff_cache.reject { |_, value| value.nil? },
50
+ added: @added_files,
51
+ removed: @removed_files.select { |f| PDK::Util::Filesystem.exist?(f) },
52
+ modified: @diff_cache.compact
53
53
  }
54
54
  end
55
55
 
@@ -115,16 +115,13 @@ module PDK
115
115
  require 'pdk/util/filesystem'
116
116
 
117
117
  if PDK::Util::Filesystem.file?(path)
118
- PDK.logger.debug("unlinking '%{path}'" % { path: path })
118
+ PDK.logger.debug(format("unlinking '%{path}'", path: path))
119
119
  PDK::Util::Filesystem.rm(path)
120
120
  else
121
- PDK.logger.debug("'%{path}': already gone" % { path: path })
121
+ PDK.logger.debug(format("'%{path}': already gone", path: path))
122
122
  end
123
- rescue => e
124
- raise PDK::CLI::ExitWithError, "Unable to remove '%{path}': %{message}" % {
125
- path: path,
126
- message: e.message,
127
- }
123
+ rescue StandardError => e
124
+ raise PDK::CLI::ExitWithError, format("Unable to remove '%{path}': %{message}", path: path, message: e.message)
128
125
  end
129
126
 
130
127
  private
@@ -140,9 +137,7 @@ module PDK
140
137
  @modified_files.each do |file|
141
138
  next if @diff_cache.key?(file[:path])
142
139
 
143
- unless PDK::Util::Filesystem.readable?(file[:path])
144
- raise PDK::CLI::ExitWithError, "Unable to open '%{path}' for reading" % { path: file[:path] }
145
- end
140
+ raise PDK::CLI::ExitWithError, format("Unable to open '%{path}' for reading", path: file[:path]) unless PDK::Util::Filesystem.readable?(file[:path])
146
141
 
147
142
  old_content = PDK::Util::Filesystem.read_file(file[:path])
148
143
  file_diff = unified_diff(file[:path], old_content, file[:content])
@@ -160,10 +155,10 @@ module PDK
160
155
  require 'pdk/util/filesystem'
161
156
 
162
157
  PDK::Util::Filesystem.mkdir_p(File.dirname(path))
163
- PDK.logger.debug("writing '%{path}'" % { path: path })
158
+ PDK.logger.debug(format("writing '%{path}'", path: path))
164
159
  PDK::Util::Filesystem.write_file(path, content)
165
160
  rescue Errno::EACCES
166
- raise PDK::CLI::ExitWithError, "You do not have permission to write to '%{path}'" % { path: path }
161
+ raise PDK::CLI::ExitWithError, format("You do not have permission to write to '%{path}'", path: path)
167
162
  end
168
163
 
169
164
  # Generate a unified diff of the changes to be made to a file.
@@ -203,19 +198,17 @@ module PDK
203
198
  file_length_difference = 0
204
199
 
205
200
  diffs.each do |piece|
206
- begin
207
- hunk = Diff::LCS::Hunk.new(old_lines, new_lines, piece, lines_of_context, file_length_difference)
208
- file_length_difference = hunk.file_length_difference
201
+ hunk = Diff::LCS::Hunk.new(old_lines, new_lines, piece, lines_of_context, file_length_difference)
202
+ file_length_difference = hunk.file_length_difference
209
203
 
210
- next unless oldhunk
204
+ next unless oldhunk
211
205
 
212
- # If the hunk overlaps with the oldhunk, merge them.
213
- next if lines_of_context > 0 && hunk.merge(oldhunk)
206
+ # If the hunk overlaps with the oldhunk, merge them.
207
+ next if lines_of_context.positive? && hunk.merge(oldhunk)
214
208
 
215
- output << oldhunk.diff(:unified)
216
- ensure
217
- oldhunk = hunk
218
- end
209
+ output << oldhunk.diff(:unified)
210
+ ensure
211
+ oldhunk = hunk
219
212
  end
220
213
 
221
214
  output << oldhunk.diff(:unified)
data/lib/pdk/module.rb CHANGED
@@ -15,7 +15,7 @@ module PDK
15
15
  '/REVISION',
16
16
  '/spec/fixtures/modules/',
17
17
  '/vendor/',
18
- '.DS_Store',
18
+ '.DS_Store'
19
19
  ].freeze
20
20
 
21
21
  def default_ignored_pathspec(ignore_dotfiles = true)
@@ -0,0 +1,268 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OS
4
+ # Os detection: Are we on Windows?
5
+ def self.windows?
6
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
7
+ end
8
+ end
9
+
10
+ # Patch childprocess so that it is Ruby 3 compliant.
11
+ # This could be removed if the following PR is ever merged
12
+ # and released:
13
+ # https://github.com/enkessler/childprocess/pull/185
14
+ module ChildProcess
15
+ class << self
16
+ def build(*args)
17
+ case os
18
+ when :macosx, :linux, :solaris, :bsd, :cygwin, :aix
19
+ if posix_spawn?
20
+ Unix::PosixSpawnProcess.new(*args)
21
+ elsif jruby?
22
+ JRuby::Process.new(*args)
23
+ else
24
+ Unix::ForkExecProcess.new(*args)
25
+ end
26
+ when :windows
27
+ Windows::Process.new(*args)
28
+ else
29
+ raise Error, "unsupported platform #{platform_name.inspect}"
30
+ end
31
+ end
32
+ end
33
+
34
+ class AbstractProcess
35
+ def initialize(*args)
36
+ raise ArgumentError, "all arguments must be String: #{args.inspect}" unless args.all?(String)
37
+
38
+ @args = args
39
+ @started = false
40
+ @exit_code = nil
41
+ @io = nil
42
+ @cwd = nil
43
+ @detach = false
44
+ @duplex = false
45
+ @leader = false
46
+ @environment = {}
47
+ end
48
+ end
49
+
50
+ if OS.windows?
51
+ module Windows
52
+ module Lib
53
+ extend FFI::Library
54
+ def self.msvcrt_name
55
+ RbConfig::CONFIG['RUBY_SO_NAME'][/msvc\w+/] || 'ucrtbase'
56
+ end
57
+
58
+ ffi_lib 'kernel32', msvcrt_name
59
+ ffi_convention :stdcall
60
+
61
+ # We have to redefine the function declarations so that they are available
62
+ # with the patched ffi_lib.
63
+ enum :wait_status, [
64
+ :wait_object_0, 0, # rubocop:disable Naming/VariableNumber
65
+ :wait_timeout, 0x102,
66
+ :wait_abandoned, 0x80,
67
+ :wait_failed, 0xFFFFFFFF
68
+ ]
69
+
70
+ #
71
+ # BOOL WINAPI CreateProcess(
72
+ # __in_opt LPCTSTR lpApplicationName,
73
+ # __inout_opt LPTSTR lpCommandLine,
74
+ # __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes,
75
+ # __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes,
76
+ # __in BOOL bInheritHandles,
77
+ # __in DWORD dwCreationFlags,
78
+ # __in_opt LPVOID lpEnvironment,
79
+ # __in_opt LPCTSTR lpCurrentDirectory,
80
+ # __in LPSTARTUPINFO lpStartupInfo,
81
+ # __out LPPROCESS_INFORMATION lpProcessInformation
82
+ # );
83
+ #
84
+
85
+ attach_function :create_process, :CreateProcessW, [
86
+ :pointer,
87
+ :buffer_inout,
88
+ :pointer,
89
+ :pointer,
90
+ :bool,
91
+ :ulong,
92
+ :pointer,
93
+ :pointer,
94
+ :pointer,
95
+ :pointer
96
+ ], :bool
97
+
98
+ #
99
+ # DWORD WINAPI FormatMessage(
100
+ # __in DWORD dwFlags,
101
+ # __in_opt LPCVOID lpSource,
102
+ # __in DWORD dwMessageId,
103
+ # __in DWORD dwLanguageId,
104
+ # __out LPTSTR lpBuffer,
105
+ # __in DWORD nSize,
106
+ # __in_opt va_list *Arguments
107
+ # );
108
+ #
109
+
110
+ attach_function :format_message, :FormatMessageA, [
111
+ :ulong,
112
+ :pointer,
113
+ :ulong,
114
+ :ulong,
115
+ :pointer,
116
+ :ulong,
117
+ :pointer
118
+ ], :ulong
119
+
120
+ attach_function :close_handle, :CloseHandle, [:pointer], :bool
121
+
122
+ #
123
+ # HANDLE WINAPI OpenProcess(
124
+ # __in DWORD dwDesiredAccess,
125
+ # __in BOOL bInheritHandle,
126
+ # __in DWORD dwProcessId
127
+ # );
128
+ #
129
+
130
+ attach_function :open_process, :OpenProcess, [:ulong, :bool, :ulong], :pointer
131
+
132
+ #
133
+ # HANDLE WINAPI CreateJobObject(
134
+ # _In_opt_ LPSECURITY_ATTRIBUTES lpJobAttributes,
135
+ # _In_opt_ LPCTSTR lpName
136
+ # );
137
+ #
138
+
139
+ attach_function :create_job_object, :CreateJobObjectA, [:pointer, :pointer], :pointer
140
+
141
+ #
142
+ # BOOL WINAPI AssignProcessToJobObject(
143
+ # _In_ HANDLE hJob,
144
+ # _In_ HANDLE hProcess
145
+ # );
146
+
147
+ attach_function :assign_process_to_job_object, :AssignProcessToJobObject, [:pointer, :pointer], :bool
148
+
149
+ #
150
+ # BOOL WINAPI SetInformationJobObject(
151
+ # _In_ HANDLE hJob,
152
+ # _In_ JOBOBJECTINFOCLASS JobObjectInfoClass,
153
+ # _In_ LPVOID lpJobObjectInfo,
154
+ # _In_ DWORD cbJobObjectInfoLength
155
+ # );
156
+ #
157
+
158
+ attach_function :set_information_job_object, :SetInformationJobObject, [:pointer, :int, :pointer, :ulong], :bool
159
+
160
+ #
161
+ #
162
+ # DWORD WINAPI WaitForSingleObject(
163
+ # __in HANDLE hHandle,
164
+ # __in DWORD dwMilliseconds
165
+ # );
166
+ #
167
+
168
+ attach_function :wait_for_single_object, :WaitForSingleObject, [:pointer, :ulong], :wait_status, blocking: true
169
+
170
+ #
171
+ # BOOL WINAPI GetExitCodeProcess(
172
+ # __in HANDLE hProcess,
173
+ # __out LPDWORD lpExitCode
174
+ # );
175
+ #
176
+
177
+ attach_function :get_exit_code, :GetExitCodeProcess, [:pointer, :pointer], :bool
178
+
179
+ #
180
+ # BOOL WINAPI GenerateConsoleCtrlEvent(
181
+ # __in DWORD dwCtrlEvent,
182
+ # __in DWORD dwProcessGroupId
183
+ # );
184
+ #
185
+
186
+ attach_function :generate_console_ctrl_event, :GenerateConsoleCtrlEvent, [:ulong, :ulong], :bool
187
+
188
+ #
189
+ # BOOL WINAPI TerminateProcess(
190
+ # __in HANDLE hProcess,
191
+ # __in UINT uExitCode
192
+ # );
193
+ #
194
+
195
+ attach_function :terminate_process, :TerminateProcess, [:pointer, :uint], :bool
196
+
197
+ #
198
+ # intptr_t _get_osfhandle(
199
+ # int fd
200
+ # );
201
+ #
202
+
203
+ attach_function :get_osfhandle, :_get_osfhandle, [:int], :intptr_t
204
+
205
+ #
206
+ # int _open_osfhandle (
207
+ # intptr_t osfhandle,
208
+ # int flags
209
+ # );
210
+ #
211
+
212
+ attach_function :open_osfhandle, :_open_osfhandle, [:pointer, :int], :int
213
+
214
+ # BOOL WINAPI SetHandleInformation(
215
+ # __in HANDLE hObject,
216
+ # __in DWORD dwMask,
217
+ # __in DWORD dwFlags
218
+ # );
219
+
220
+ attach_function :set_handle_information, :SetHandleInformation, [:pointer, :ulong, :ulong], :bool
221
+
222
+ # BOOL WINAPI GetHandleInformation(
223
+ # __in HANDLE hObject,
224
+ # __out LPDWORD lpdwFlags
225
+ # );
226
+
227
+ attach_function :get_handle_information, :GetHandleInformation, [:pointer, :pointer], :bool
228
+
229
+ # BOOL WINAPI CreatePipe(
230
+ # __out PHANDLE hReadPipe,
231
+ # __out PHANDLE hWritePipe,
232
+ # __in_opt LPSECURITY_ATTRIBUTES lpPipeAttributes,
233
+ # __in DWORD nSize
234
+ # );
235
+
236
+ attach_function :create_pipe, :CreatePipe, [:pointer, :pointer, :pointer, :ulong], :bool
237
+
238
+ #
239
+ # HANDLE WINAPI GetCurrentProcess(void);
240
+ #
241
+
242
+ attach_function :current_process, :GetCurrentProcess, [], :pointer
243
+
244
+ #
245
+ # BOOL WINAPI DuplicateHandle(
246
+ # __in HANDLE hSourceProcessHandle,
247
+ # __in HANDLE hSourceHandle,
248
+ # __in HANDLE hTargetProcessHandle,
249
+ # __out LPHANDLE lpTargetHandle,
250
+ # __in DWORD dwDesiredAccess,
251
+ # __in BOOL bInheritHandle,
252
+ # __in DWORD dwOptions
253
+ # );
254
+ #
255
+
256
+ attach_function :_duplicate_handle, :DuplicateHandle, [
257
+ :pointer,
258
+ :pointer,
259
+ :pointer,
260
+ :pointer,
261
+ :ulong,
262
+ :bool,
263
+ :ulong
264
+ ], :bool
265
+ end
266
+ end
267
+ end
268
+ end
@@ -194,13 +194,9 @@ module PDK
194
194
  # @raise [ArgumentError] if the value is nil, an empty String, or not
195
195
  # a String.
196
196
  def sanitise_file(value)
197
- if value.nil? || (value.is_a?(String) && value.empty?)
198
- raise ArgumentError, 'File not specified.'
199
- end
197
+ raise ArgumentError, 'File not specified.' if value.nil? || (value.is_a?(String) && value.empty?)
200
198
 
201
- unless value.is_a?(String)
202
- raise ArgumentError, 'File must be a String.'
203
- end
199
+ raise ArgumentError, 'File must be a String.' unless value.is_a?(String)
204
200
 
205
201
  require 'pathname'
206
202
  require 'pdk/util'
@@ -234,22 +230,13 @@ module PDK
234
230
  # @raise [ArgumentError] if the value is nil, an empty String, or not
235
231
  # a String or Symbol representation of a valid state.
236
232
  def sanitise_state(value)
237
- if value.nil? || (value.is_a?(String) && value.empty?)
238
- raise ArgumentError, 'State not specified.'
239
- end
233
+ raise ArgumentError, 'State not specified.' if value.nil? || (value.is_a?(String) && value.empty?)
240
234
 
241
235
  value = value.to_sym if value.is_a?(String)
242
- unless value.is_a?(Symbol)
243
- raise ArgumentError, 'State must be a Symbol, not %{type}' % { type: value.class }
244
- end
236
+ raise ArgumentError, format('State must be a Symbol, not %{type}', type: value.class) unless value.is_a?(Symbol)
245
237
 
246
238
  valid_states = [:passed, :error, :failure, :skipped]
247
- unless valid_states.include?(value)
248
- raise ArgumentError, 'Invalid state %{state}. Valid states are: %{valid}.' % {
249
- state: value.inspect,
250
- valid: valid_states.map(&:inspect).join(', '),
251
- }
252
- end
239
+ raise ArgumentError, format('Invalid state %{state}. Valid states are: %{valid}.', state: value.inspect, valid: valid_states.map(&:inspect).join(', ')) unless valid_states.include?(value)
253
240
 
254
241
  value
255
242
  end
@@ -263,9 +250,7 @@ module PDK
263
250
  #
264
251
  # @raise [ArgumentError] if the value is nil or an empty String.
265
252
  def sanitise_source(value)
266
- if value.nil? || (value.is_a?(String) && value.empty?)
267
- raise ArgumentError, 'Source not specified.'
268
- end
253
+ raise ArgumentError, 'Source not specified.' if value.nil? || (value.is_a?(String) && value.empty?)
269
254
 
270
255
  value.to_s
271
256
  end
@@ -284,13 +269,9 @@ module PDK
284
269
  valid_types << Fixnum # rubocop:disable Lint/UnifiedInteger
285
270
  end
286
271
 
287
- unless valid_types.include?(value.class)
288
- raise ArgumentError, 'Line must be an Integer or a String representation of an Integer.'
289
- end
272
+ raise ArgumentError, 'Line must be an Integer or a String representation of an Integer.' unless valid_types.include?(value.class)
290
273
 
291
- if value.is_a?(String) && value !~ %r{\A[0-9]+\Z}
292
- raise ArgumentError, 'The line number can contain only the digits 0-9.'
293
- end
274
+ raise ArgumentError, 'The line number can contain only the digits 0-9.' if value.is_a?(String) && value !~ /\A[0-9]+\Z/
294
275
 
295
276
  value.to_i
296
277
  end
@@ -309,13 +290,9 @@ module PDK
309
290
  valid_types << Fixnum # rubocop:disable Lint/UnifiedInteger
310
291
  end
311
292
 
312
- unless valid_types.include?(value.class)
313
- raise ArgumentError, 'Column must be an Integer or a String representation of an Integer.'
314
- end
293
+ raise ArgumentError, 'Column must be an Integer or a String representation of an Integer.' unless valid_types.include?(value.class)
315
294
 
316
- if value.is_a?(String) && value !~ %r{\A[0-9]+\Z}
317
- raise ArgumentError, 'The column number can contain only the digits 0-9.'
318
- end
295
+ raise ArgumentError, 'The column number can contain only the digits 0-9.' if value.is_a?(String) && value !~ /\A[0-9]+\Z/
319
296
 
320
297
  value.to_i
321
298
  end
@@ -331,14 +308,12 @@ module PDK
331
308
 
332
309
  valid_types = [Array]
333
310
 
334
- unless valid_types.include?(value.class)
335
- raise ArgumentError, 'Trace must be an Array of stack trace lines.'
336
- end
311
+ raise ArgumentError, 'Trace must be an Array of stack trace lines.' unless valid_types.include?(value.class)
337
312
 
338
313
  # Drop any stacktrace lines that include '/gems/' in the path or
339
314
  # are the original rspec binstub lines
340
315
  value.reject do |line|
341
- (line =~ %r{/gems/}) || (line =~ %r{bin/rspec:})
316
+ line.include?('/gems/') || line.include?('bin/rspec:')
342
317
  end
343
318
  end
344
319
 
data/lib/pdk/report.rb CHANGED
@@ -6,7 +6,7 @@ module PDK
6
6
 
7
7
  # @return [Array<String>] the list of supported report formats.
8
8
  def self.formats
9
- @report_formats ||= %w[junit text].freeze
9
+ @report_formats ||= ['junit', 'text'].freeze
10
10
  end
11
11
 
12
12
  # @return [Symbol] the method name of the default report format.
@@ -60,9 +60,9 @@ module PDK
60
60
  testsuite = REXML::Element.new('testsuite')
61
61
  testsuite.attributes['name'] = testsuite_name
62
62
  testsuite.attributes['tests'] = testcases.length
63
- testsuite.attributes['errors'] = testcases.select(&:error?).length
64
- testsuite.attributes['failures'] = testcases.select(&:failure?).length
65
- testsuite.attributes['skipped'] = testcases.select(&:skipped?).length
63
+ testsuite.attributes['errors'] = testcases.count(&:error?)
64
+ testsuite.attributes['failures'] = testcases.count(&:failure?)
65
+ testsuite.attributes['skipped'] = testcases.count(&:skipped?)
66
66
  testsuite.attributes['time'] = 0
67
67
  testsuite.attributes['timestamp'] = Time.now.strftime('%Y-%m-%dT%H:%M:%S')
68
68
  testsuite.attributes['hostname'] = Socket.gethostname
@@ -14,6 +14,7 @@ module PDK
14
14
  # @see PDK::Template::Fetcher::AbstractTemplateFetcher.fetch!
15
15
  def fetch!
16
16
  return if fetched
17
+
17
18
  super
18
19
 
19
20
  # Default metadata for all git fetching methods
@@ -22,9 +23,7 @@ module PDK
22
23
  # We don't do a checkout of local-path repos. There are lots of edge
23
24
  # cases or user un-expectations.
24
25
  if PDK::Util::Git.work_tree?(uri.shell_path)
25
- PDK.logger.warn "Repository '%{repo}' has a work-tree; skipping git reset." % {
26
- repo: uri.shell_path,
27
- }
26
+ PDK.logger.warn format("Repository '%{repo}' has a work-tree; skipping git reset.", repo: uri.shell_path)
28
27
  @path = uri.shell_path
29
28
  @temporary = false
30
29
  @metadata['template-ref'] = describe_path_and_ref(@path)
@@ -49,7 +48,7 @@ module PDK
49
48
  unless clone_result[:exit_code].zero?
50
49
  PDK.logger.error clone_result[:stdout]
51
50
  PDK.logger.error clone_result[:stderr]
52
- raise PDK::CLI::FatalError, "Unable to clone git repository at '%{repo}' into '%{dest}'." % { repo: origin_repo, dest: temp_dir }
51
+ raise PDK::CLI::FatalError, format("Unable to clone git repository at '%{repo}' into '%{dest}'.", repo: origin_repo, dest: temp_dir)
53
52
  end
54
53
  @path = PDK::Util.canonical_path(temp_dir)
55
54
 
@@ -63,22 +62,22 @@ module PDK
63
62
 
64
63
  PDK.logger.error reset_result[:stdout]
65
64
  PDK.logger.error reset_result[:stderr]
66
- raise PDK::CLI::FatalError, "Unable to checkout '%{ref}' of git repository at '%{path}'." % { ref: git_ref, path: temp_dir }
65
+ raise PDK::CLI::FatalError, format("Unable to checkout '%{ref}' of git repository at '%{path}'.", ref: git_ref, path: temp_dir)
67
66
  end
68
67
  else
69
- PDK.logger.warn "Uncommitted changes found when attempting to checkout '%{ref}' of git repository at '%{path}'; skipping git reset." % { ref: git_ref, path: temp_dir }
68
+ PDK.logger.warn format("Uncommitted changes found when attempting to checkout '%{ref}' of git repository at '%{path}'; skipping git reset.", ref: git_ref, path: temp_dir)
70
69
  @metadata['template-ref'] = describe_path_and_ref(temp_dir)
71
70
  end
72
71
  end
73
72
 
74
73
  private
75
74
 
76
- #:nocov: This is a just a wrapper for another method
75
+ # :nocov: This is a just a wrapper for another method
77
76
  def describe_path_and_ref(path, ref = nil)
78
77
  require 'pdk/util/git'
79
78
  PDK::Util::Git.describe(File.join(path, '.git'), ref)
80
79
  end
81
- #:nocov:
80
+ # :nocov:
82
81
  end
83
82
  end
84
83
  end
@@ -16,6 +16,7 @@ module PDK
16
16
  # @see PDK::Template::Fetcher::AbstractTemplateFetcher.fetch!
17
17
  def fetch!
18
18
  return if fetched
19
+
19
20
  super
20
21
 
21
22
  @path = uri.shell_path
@@ -13,6 +13,7 @@ module PDK
13
13
  # @return [PDK::Template::Fetcher::AbstractTemplateFetcher] An instance of a class which implements the AbstractFetcher class
14
14
  def self.instance(uri, options = {})
15
15
  return Git.new(uri, options) if Git.fetchable?(uri, options)
16
+
16
17
  Local.new(uri, options)
17
18
  end
18
19
 
@@ -35,7 +36,8 @@ module PDK
35
36
  # @raise [ArgumentError] If no block is given to this method.
36
37
  # @return [void]
37
38
  def self.with(uri, options = {})
38
- raise ArgumentError, '%{class_name}.with must be passed a block.' % { class_name: name } unless block_given?
39
+ raise ArgumentError, format('%{class_name}.with must be passed a block.', class_name: name) unless block_given?
40
+
39
41
  fetcher = instance(uri, options)
40
42
 
41
43
  begin
@@ -78,7 +80,7 @@ module PDK
78
80
  @metadata = {
79
81
  'pdk-version' => PDK::Util::Version.version_string,
80
82
  'template-url' => nil,
81
- 'template-ref' => nil,
83
+ 'template-ref' => nil
82
84
  }
83
85
  @fetched = false
84
86
  @temporary = false
@@ -65,7 +65,7 @@ module PDK
65
65
  'unmanaged'
66
66
  elsif c['delete']
67
67
  'deleted'
68
- elsif @sync_config && @sync_config.key?(dest_path)
68
+ elsif @sync_config&.key?(dest_path)
69
69
  'customized'
70
70
  else
71
71
  'default'
@@ -91,15 +91,10 @@ module PDK
91
91
  require 'yaml'
92
92
 
93
93
  begin
94
- YAML.safe_load(PDK::Util::Filesystem.read_file(loc), [], [], true)
94
+ YAML.safe_load(PDK::Util::Filesystem.read_file(loc), permitted_classes: [], permitted_symbols: [], aliases: true)
95
95
  rescue Psych::SyntaxError => e
96
- PDK.logger.warn "'%{file}' is not a valid YAML file: %{problem} %{context} at line %{line} column %{column}" % {
97
- file: loc,
98
- problem: e.problem,
99
- context: e.context,
100
- line: e.line,
101
- column: e.column,
102
- }
96
+ PDK.logger.warn format("'%{file}' is not a valid YAML file: %{problem} %{context} at line %{line} column %{column}", file: loc, problem: e.problem, context: e.context, line: e.line,
97
+ column: e.column)
103
98
  {}
104
99
  end
105
100
  else