[Pkg-puppet-devel] [facter] 158/352: (FACT-207) Simplify Fact options hash evaluation

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:41 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 9a02a2fa348cc5621acdf959bfd10c34fe2f1ee2
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Wed Jan 15 16:23:46 2014 -0800

    (FACT-207) Simplify Fact options hash evaluation
    
    Facts only accept the :ldapname option which is deprecated, and it
    doesn't look like there will be any other options added. This commit
    simplifies the options hash parsing and modifies the hash in place so
    that other objects don't have to know about extra hash options.
---
 lib/facter/util/fact.rb     | 19 +++++++------------
 spec/unit/util/fact_spec.rb |  4 ----
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/lib/facter/util/fact.rb b/lib/facter/util/fact.rb
index 203635b..663c155 100644
--- a/lib/facter/util/fact.rb
+++ b/lib/facter/util/fact.rb
@@ -26,7 +26,7 @@ class Facter::Util::Fact
   def initialize(name, options = {})
     @name = name.to_s.downcase.intern
 
-    set_options(options)
+    extract_ldapname_option!(options)
 
     @ldapname ||= @name.to_s
 
@@ -126,17 +126,12 @@ class Facter::Util::Fact
     end
   end
 
-  def set_options(options)
-    # LAK:NOTE: This is slow for many options, but generally we won't have any and at
-    # worst we'll have one.  If we add more, this should be made more efficient.
-    options.each do |name, value|
-      case name
-      when :ldapname
-        Facter.warnonce("ldapname is deprecated and will be removed in a future version")
-        self.ldapname = value
-      else
-        raise ArgumentError, "Invalid fact option '%s'" % name
-      end
+  # @api private
+  # @deprecated
+  def extract_ldapname_option!(options)
+    if options[:ldapname]
+      Facter.warnonce("ldapname is deprecated and will be removed in a future version")
+      self.ldapname = options.delete(:ldapname)
     end
   end
 
diff --git a/spec/unit/util/fact_spec.rb b/spec/unit/util/fact_spec.rb
index a22f3e9..3e2f20e 100755
--- a/spec/unit/util/fact_spec.rb
+++ b/spec/unit/util/fact_spec.rb
@@ -17,10 +17,6 @@ describe Facter::Util::Fact do
     Facter::Util::Fact.new("YayNess", :ldapname => "fooness")
   end
 
-  it "should fail if an unknown option is provided" do
-    lambda { Facter::Util::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError)
-  end
-
   it "should have a method for adding resolution mechanisms" do
     Facter::Util::Fact.new("yay").should respond_to(:add)
   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