ruby-pwsh 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e217873cdddb9b32ba467e0a9f5de6977c04b11a1c0788613dda6181e96a62bd
4
- data.tar.gz: 8dc82dfad8869d7c632ba3d902b4e22c375aeb5988f84e359269163da885b604
3
+ metadata.gz: 106716635e03eef49ab00c8dd35cf16a5674a27452968b16ba7756ba252b97be
4
+ data.tar.gz: 4bd6c34343347a1d705cea410346028bbb91446bf5983e75409f16c7730f1000
5
5
  SHA512:
6
- metadata.gz: a7e02f1cee48fa49316c133268a16f9bc3b8f195927834854c81eee134cdb7056710cd1be04eaf992ca036aa2b014175d06ebf8684eef6354ef8d10a07a62e31
7
- data.tar.gz: da78f276002b67faf3716ce0b8157fe3cf0edbbeb5da3ae1145c3ed696e386838285138fdd0c75b8a592b677b7631c66ce07355a25788dee58354af0ecdd9eaa
6
+ metadata.gz: f8b6c0c4ff6eabbc9a842cc863d76128dbccca74fabfef02b4aea6ba54f3a01ffd3d97447df4ccc027a8f22cf6a7b430b0893e34d0de7989e742442cf56b5ef9
7
+ data.tar.gz: 2404be74308d1b80c5d8f775f49f0f0ac6ae7deab47fe7c38e25e79852aac42f87e16b5cea5e4a4617cdde6eac1236cc8407a0e10fe2c9198bcfd0d6e88a7548
data/README.md CHANGED
@@ -85,6 +85,7 @@ The following platforms are supported:
85
85
  - OSX
86
86
  - RedHat
87
87
  - Ubuntu
88
+ - AlmaLinux
88
89
 
89
90
  ## Limitations
90
91
 
@@ -682,16 +682,16 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
682
682
  context.type.attributes.select { |_attribute, properties| properties[:mandatory_for_set] }.keys
683
683
  end
684
684
 
685
- # Parses the DSC resource type definition to retrieve the names of any attributes which are specified as required strings
686
- # This is used to ensure that any nil values are converted to empty strings to match puppets expected value
685
+ # Parses the DSC resource type definition to retrieve the names of any attributes which are specifed as required strings
686
+ # This is used to ensure that any nil values are converted to empty strings to match puppets expecetd value
687
687
  # @param context [Object] the Puppet runtime context to operate in and send feedback to
688
688
  # @param data [Hash] the hash of properties returned from the DSC resource
689
689
  # @return [Hash] returns a data hash with any nil values converted to empty strings
690
690
  def stringify_nil_attributes(context, data)
691
- nil_attributes = data.select { |_name, value| value.nil? }.keys
692
- nil_attributes.each do |nil_attr|
693
- attribute_type = context.type.attributes[nil_attr][:type]
694
- data[nil_attr] = '' if (attribute_type.include?('Enum[') && enum_values(context, nil_attr).include?('')) || attribute_type == 'String'
691
+ nil_strings = data.select { |_name, value| value.nil? }.keys
692
+ string_attrs = context.type.attributes.select { |_name, properties| properties[:type] == 'String' }.keys
693
+ string_attrs.each do |attribute|
694
+ data[attribute] = '' if nil_strings.include?(attribute)
695
695
  end
696
696
  data
697
697
  end
@@ -123,4 +123,4 @@ Function ConvertTo-CanonicalResult {
123
123
 
124
124
  # Output the final result
125
125
  $ResultObject
126
- }
126
+ }
data/lib/pwsh/util.rb CHANGED
@@ -15,20 +15,16 @@ module Pwsh
15
15
  !!(host_os =~ /mswin|mingw/)
16
16
  end
17
17
 
18
- # Verify paths specified are valid directories which exist.
19
- #
20
- # @return [Bool] true if any directories specified do not exist
18
+ # Verify paths specified are valid directories.
19
+ # Skips paths which do not exist.
20
+ # @return [Bool] true if any paths specified are not valid directories
21
21
  def invalid_directories?(path_collection)
22
- invalid_paths = false
23
-
24
- return invalid_paths if path_collection.nil? || path_collection.empty?
22
+ return false if path_collection.nil? || path_collection.empty?
25
23
 
26
- paths = on_windows? ? path_collection.split(';') : path_collection.split(':')
27
- paths.each do |path|
28
- invalid_paths = true unless File.directory?(path) || path.empty?
29
- end
24
+ delimiter = on_windows? ? ';' : ':'
25
+ paths = path_collection.split(delimiter)
30
26
 
31
- invalid_paths
27
+ paths.any? { |path| !path.empty? && File.exist?(path) && !File.directory?(path) }
32
28
  end
33
29
 
34
30
  # Return a string or symbol converted to snake_case
data/lib/pwsh/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Pwsh
4
4
  # The version of the ruby-pwsh gem
5
- VERSION = '1.2.0'
5
+ VERSION = '1.2.1'
6
6
  end
data/lib/pwsh.rb CHANGED
@@ -108,7 +108,7 @@ module Pwsh
108
108
  @powershell_command = cmd
109
109
  @powershell_arguments = args
110
110
 
111
- raise "Bad configuration for ENV['lib']=#{ENV['lib']} - invalid path" if Pwsh::Util.invalid_directories?(ENV['lib'])
111
+ warn "Bad configuration for ENV['lib']=#{ENV['lib']} - invalid path" if Pwsh::Util.invalid_directories?(ENV['lib'])
112
112
 
113
113
  if Pwsh::Util.on_windows?
114
114
  # Named pipes under Windows will automatically be mounted in \\.\pipe\...
@@ -87,13 +87,15 @@ RSpec.describe Pwsh::Util do
87
87
  end
88
88
 
89
89
  describe '.invalid_directories?' do
90
- let(:valid_path_a) { 'C:/some/folder' }
91
- let(:valid_path_b) { 'C:/another/folder' }
92
- let(:valid_paths) { 'C:/some/folder;C:/another/folder' }
93
- let(:invalid_path) { 'C:/invalid/path' }
94
- let(:mixed_paths) { 'C:/some/folder;C:/invalid/path;C:/another/folder' }
95
- let(:empty_string) { '' }
96
- let(:empty_members) { 'C:/some/folder;;C:/another/folder' }
90
+ let(:valid_path_a) { 'C:/some/folder' }
91
+ let(:valid_path_b) { 'C:/another/folder' }
92
+ let(:valid_paths) { 'C:/some/folder;C:/another/folder' }
93
+ let(:invalid_path) { 'C:/invalid/path' }
94
+ let(:mixed_paths) { 'C:/some/folder;C:/another/folder;C:/invalid/path' }
95
+ let(:empty_string) { '' }
96
+ let(:file_path) { 'C:/some/folder/file.txt' }
97
+ let(:non_existent_dir) { 'C:/some/dir/that/doesnt/exist' }
98
+ let(:empty_members) { 'C:/some/folder;;C:/another/folder' }
97
99
 
98
100
  it 'returns false if passed nil' do
99
101
  expect(described_class.invalid_directories?(nil)).to be false
@@ -103,8 +105,16 @@ RSpec.describe Pwsh::Util do
103
105
  expect(described_class.invalid_directories?('')).to be false
104
106
  end
105
107
 
108
+ it 'returns true if a file path is provided' do
109
+ expect(described_class).to receive(:on_windows?).and_return(true)
110
+ expect(File).to receive(:exist?).with(file_path).and_return(true)
111
+ expect(File).to receive(:directory?).with(file_path).and_return(false)
112
+ expect(described_class.invalid_directories?(file_path)).to be true
113
+ end
114
+
106
115
  it 'returns false if one valid path is provided' do
107
116
  expect(described_class).to receive(:on_windows?).and_return(true)
117
+ expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
108
118
  expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
109
119
  expect(described_class.invalid_directories?(valid_path_a)).to be false
110
120
  end
@@ -112,31 +122,56 @@ RSpec.describe Pwsh::Util do
112
122
  it 'returns false if a collection of valid paths is provided' do
113
123
  expect(described_class).to receive(:on_windows?).and_return(true)
114
124
  expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
125
+ expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
115
126
  expect(File).to receive(:directory?).with(valid_path_b).and_return(true)
127
+ expect(File).to receive(:exist?).with(valid_path_b).and_return(true)
116
128
  expect(described_class.invalid_directories?(valid_paths)).to be false
117
129
  end
118
130
 
119
131
  it 'returns true if there is only one path and it is invalid' do
120
132
  expect(described_class).to receive(:on_windows?).and_return(true)
133
+ expect(File).to receive(:exist?).with(invalid_path).and_return(true)
121
134
  expect(File).to receive(:directory?).with(invalid_path).and_return(false)
122
135
  expect(described_class.invalid_directories?(invalid_path)).to be true
123
136
  end
124
137
 
125
138
  it 'returns true if the collection has on valid and one invalid member' do
126
139
  expect(described_class).to receive(:on_windows?).and_return(true)
140
+ expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
127
141
  expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
142
+ expect(File).to receive(:exist?).with(valid_path_b).and_return(true)
128
143
  expect(File).to receive(:directory?).with(valid_path_b).and_return(true)
144
+ expect(File).to receive(:exist?).with(invalid_path).and_return(true)
129
145
  expect(File).to receive(:directory?).with(invalid_path).and_return(false)
130
146
  expect(described_class.invalid_directories?(mixed_paths)).to be true
131
147
  end
132
148
 
133
149
  it 'returns false if collection has empty members but other entries are valid' do
134
150
  expect(described_class).to receive(:on_windows?).and_return(true)
151
+ expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
135
152
  expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
153
+ expect(File).to receive(:exist?).with(valid_path_b).and_return(true)
136
154
  expect(File).to receive(:directory?).with(valid_path_b).and_return(true)
137
155
  allow(File).to receive(:directory?).with('')
138
156
  expect(described_class.invalid_directories?(empty_members)).to be false
139
157
  end
158
+
159
+ it 'returns true if a collection has valid members but also contains a file path' do
160
+ expect(described_class).to receive(:on_windows?).and_return(true)
161
+ expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
162
+ expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
163
+ expect(File).to receive(:exist?).with(file_path).and_return(true)
164
+ expect(File).to receive(:directory?).with(file_path).and_return(false)
165
+ expect(described_class.invalid_directories?("#{valid_path_a};#{file_path}")).to be true
166
+ end
167
+
168
+ it 'returns false if a collection has valid members but contains a non-existent dir path' do
169
+ expect(described_class).to receive(:on_windows?).and_return(true)
170
+ expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
171
+ expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
172
+ expect(File).to receive(:exist?).with(non_existent_dir).and_return(false)
173
+ expect(described_class.invalid_directories?("#{valid_path_a};#{non_existent_dir}")).to be false
174
+ end
140
175
  end
141
176
 
142
177
  describe '.snake_case' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-pwsh
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-15 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PowerShell code manager for ruby.
14
14
  email: