]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(MODULES-2316) Change file_type boolean parameter to symbols
authorDominic Cleal <dcleal@redhat.com>
Tue, 4 Aug 2015 08:59:53 +0000 (09:59 +0100)
committerDominic Cleal <dcleal@redhat.com>
Tue, 4 Aug 2015 08:59:53 +0000 (09:59 +0100)
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.

lib/puppet/provider/file_line/ruby.rb
lib/puppet/type/file_line.rb
spec/unit/puppet/provider/file_line/ruby_spec.rb
spec/unit/puppet/type/file_line_spec.rb

index ea1d44d6a20c51c577ce1ef3861d633522c0d56a..d4cdfec131863bb7d34e44eacf05d7af7cc9ef1b 100644 (file)
@@ -1,6 +1,6 @@
 Puppet::Type.type(:file_line).provide(:ruby) do
   def exists?
-    if !resource[:replace] and count_matches(match_regex) > 0
+    if resource[:replace].to_s != 'true' and count_matches(match_regex) > 0
       true
     else
       lines.find do |line|
@@ -10,7 +10,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do
   end
 
   def create
-    unless !resource[:replace] and count_matches(match_regex) > 0
+    unless resource[:replace].to_s != 'true' and count_matches(match_regex) > 0
       if resource[:match]
         handle_create_with_match
       elsif resource[:after]
index 190105ce0cf6ae9a5da6f258ddbc86adc247213b..4a96ba7ad37ef3649ef37ea6abce755290e5622a 100644 (file)
@@ -1,4 +1,3 @@
-require 'puppet/parameter/boolean'
 Puppet::Type.newtype(:file_line) do
 
   desc <<-EOT
@@ -79,8 +78,9 @@ Puppet::Type.newtype(:file_line) do
     end
   end
 
-  newparam(:replace, :boolean => true, :parent => Puppet::Parameter::Boolean) do
+  newparam(:replace) do
     desc 'If true, replace line that matches. If false, do not write line if a match is found'
+    newvalues(true, false)
     defaultto true
   end
 
index 5eff09a85596a0c3b4ce57ad9bfade457185571f..792391a75c98ef8f98d07816316d4baa9abae3e0 100755 (executable)
@@ -85,7 +85,7 @@ describe provider_class do
             :replace  => 'asgadga',
           }
         )
-      }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false, yes, no\./)
+      }.to raise_error(Puppet::Error, /Invalid value "asgadga"\. Valid values are true, false\./)
     end
   end
   context "when matching" do
index 58c88e3b49da082a61baf07a1347f0bd528f77a4..f1430f263a3fd53a9e0fc620c217e14108e212aa 100755 (executable)
@@ -50,7 +50,7 @@ describe Puppet::Type.type(:file_line) do
     expect(file_line[:ensure]).to eq :present
   end
   it 'should default to replace => true' do
-    expect(file_line[:replace]).to eq true
+    expect(file_line[:replace]).to eq :true
   end
 
   it "should autorequire the file it manages" do