[Pkg-puppet-devel] [facter] 199/352: (maint) Simplify logging controls

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 905f2090ab79d072e0a668a2da5ce4f38efd4fe4
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Mon Feb 3 10:51:13 2014 -0800

    (maint) Simplify logging controls
    
    Ruby has these neat things called booleans that we can use to indicate
    true/false values. Because of this we can directly specify the
    truthiness of something instead of accepting arbitrary strings, numbers,
    and other classes and cocercing them to booleans.
---
 lib/facter/core/logging.rb     | 61 ++++++++++++------------------------------
 spec/unit/core/logging_spec.rb | 55 +++++++++++++++----------------------
 2 files changed, 38 insertions(+), 78 deletions(-)

diff --git a/lib/facter/core/logging.rb b/lib/facter/core/logging.rb
index c466b0c..b908daf 100644
--- a/lib/facter/core/logging.rb
+++ b/lib/facter/core/logging.rb
@@ -10,9 +10,9 @@ module Facter::Core::Logging
   RESET = ""
 
   # @api private
-  @@debug = 0
+  @@debug = false
   # @api private
-  @@timing = 0
+  @@timing = false
   # @api private
   @@warn_messages = {}
   # @api private
@@ -85,67 +85,40 @@ module Facter::Core::Logging
     puts "#{GREEN}#{string}#{RESET}" if string and self.timing?
   end
 
-  # Sets debugging on or off.
+  # Enable or disable logging of debug messages
   #
+  # @param bool [true, false]
   # @return [void]
   #
   # @api private
-  def debugging(bit)
-    if bit
-      case bit
-      when TrueClass; @@debug = 1
-      when FalseClass; @@debug = 0
-      when Fixnum
-        if bit > 0
-          @@debug = 1
-        else
-          @@debug = 0
-        end
-      when String;
-        if bit.downcase == 'off'
-          @@debug = 0
-        else
-          @@debug = 1
-        end
-      else
-        @@debug = 0
-      end
-    else
-      @@debug = 0
-    end
+  def debugging(bool)
+    @@debug = bool
   end
 
-  # Returns whether debugging output is turned on
+  # Is debugging enabled?
+  #
+  # @return [true, false]
+  #
+  # @api private
   def debugging?
-    @@debug != 0
+    @@debug
   end
 
-  # Sets whether timing messages are displayed.
+  # Enable or disable logging of timing information
   #
+  # @param bool [true, false]
   # @return [void]
   #
   # @api private
-  def timing(bit)
-    if bit
-      case bit
-      when TrueClass; @@timing = 1
-      when Fixnum
-        if bit > 0
-          @@timing = 1
-        else
-          @@timing = 0
-        end
-      end
-    else
-      @@timing = 0
-    end
+  def timing(bool)
+    @@timing = bool
   end
 
   # Returns whether timing output is turned on
   #
   # @api private
   def timing?
-    @@timing != 0
+    @@timing
   end
 
   # Clears the seen state of warning messages. See {warnonce}.
diff --git a/spec/unit/core/logging_spec.rb b/spec/unit/core/logging_spec.rb
index 14e09c4..2258912 100644
--- a/spec/unit/core/logging_spec.rb
+++ b/spec/unit/core/logging_spec.rb
@@ -64,50 +64,37 @@ describe Facter::Core::Logging do
     end
   end
 
-  describe "when setting debugging mode" do
-    it "should have debugging enabled using 1" do
-      subject.debugging(1)
-      subject.should be_debugging
-    end
-    it "should have debugging enabled using true" do
+  describe "when setting the debugging mode" do
+    it "is enabled when the given value is true" do
       subject.debugging(true)
-      subject.should be_debugging
-    end
-    it "should have debugging enabled using any string except off" do
-      subject.debugging('aaaaa')
-      subject.should be_debugging
-    end
-    it "should have debugging disabled using 0" do
-      subject.debugging(0)
-      subject.should_not be_debugging
+      expect(subject.debugging?).to be_true
     end
-    it "should have debugging disabled using false" do
+
+    it "is disabled when the given value is false" do
       subject.debugging(false)
-      subject.should_not be_debugging
+      expect(subject.debugging?).to be_false
     end
-    it "should have debugging disabled using the string 'off'" do
-      subject.debugging('off')
-      subject.should_not be_debugging
+
+    it "is disabled when the given value is nil" do
+      subject.debugging(nil)
+      expect(subject.debugging?).to be_false
     end
   end
 
-  describe "when setting timing mode" do
-    it "should have timing enabled using 1" do
-      subject.timing(1)
-      subject.should be_timing
-    end
-    it "should have timing enabled using true" do
+  describe "when setting the timing mode" do
+    it "is enabled when the given value is true" do
       subject.timing(true)
-      subject.should be_timing
+      expect(subject.timing?).to be_true
     end
-    it "should have timing disabled using 0" do
-      subject.timing(0)
-      subject.should_not be_timing
-    end
-    it "should have timing disabled using false" do
+
+    it "is disabled when the given value is false" do
       subject.timing(false)
-      subject.should_not be_timing
+      expect(subject.timing?).to be_false
     end
-  end
 
+    it "is disabled when the given value is nil" do
+      subject.timing(nil)
+      expect(subject.timing?).to be_false
+    end
+  end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list