Skip to content

Commit a7adcda

Browse files
author
Dominic Cleal
committed
(MODULES-2316) Change file_type boolean parameter to symbols
Puppet's boolean parameter type is only available in Puppet 3.3 and higher, so change file_type's new "replace" parameter to a regular parameter with true and false as possible values. This matches the existing "multiple" parameter.
1 parent e815da5 commit a7adcda

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

lib/puppet/provider/file_line/ruby.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Puppet::Type.type(:file_line).provide(:ruby) do
22
def exists?
3-
if !resource[:replace] and count_matches(match_regex) > 0
3+
if resource[:replace].to_s != 'true' and count_matches(match_regex) > 0
44
true
55
else
66
lines.find do |line|
@@ -10,7 +10,7 @@ def exists?
1010
end
1111

1212
def create
13-
unless !resource[:replace] and count_matches(match_regex) > 0
13+
unless resource[:replace].to_s != 'true' and count_matches(match_regex) > 0
1414
if resource[:match]
1515
handle_create_with_match
1616
elsif resource[:after]

lib/puppet/type/file_line.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
require 'puppet/parameter/boolean'
21
Puppet::Type.newtype(:file_line) do
32

43
desc <<-EOT
@@ -79,8 +78,9 @@
7978
end
8079
end
8180

82-
newparam(:replace, :boolean => true, :parent => Puppet::Parameter::Boolean) do
81+
newparam(:replace) do
8382
desc 'If true, replace line that matches. If false, do not write line if a match is found'
83+
newvalues(true, false)
8484
defaultto true
8585
end
8686

spec/unit/puppet/provider/file_line/ruby_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
:replace => 'asgadga',
8686
}
8787
)
88-
}.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false, yes, no\./)
88+
}.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false\./)
8989
end
9090
end
9191
context "when matching" do

spec/unit/puppet/type/file_line_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
expect(file_line[:ensure]).to eq :present
5151
end
5252
it 'should default to replace => true' do
53-
expect(file_line[:replace]).to eq true
53+
expect(file_line[:replace]).to eq :true
5454
end
5555

5656
it "should autorequire the file it manages" do

0 commit comments

Comments
 (0)