[Pkg-puppet-devel] [facter] 207/352: (maint) Remove Facter.method_missing
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:46 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 a0391397cfcaece697c4a28982e97382718db473
Author: Adrien Thebo <git at somethingsinistral.net>
Date: Mon Feb 3 16:03:12 2014 -0800
(maint) Remove Facter.method_missing
The ability to use method_missing was added in 2006 but was never
documented, explained, or generally acknowledge. It was a constant
surprise when invoking a non-existent method on Facter would cause all
facts to be loaded and possibly a completely nonsensical value would be
returned. This commit removes the given code so we can return to a more
sane state of affairs.
---
lib/facter.rb | 33 ---------------------------------
lib/facter/util/netmask.rb | 4 ++--
spec/unit/facter_spec.rb | 16 ----------------
3 files changed, 2 insertions(+), 51 deletions(-)
diff --git a/lib/facter.rb b/lib/facter.rb
index 2244912..6277aeb 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -166,39 +166,6 @@ module Facter
end
end
- class << self
- # Allow users to call fact names directly on the Facter class,
- # either retrieving the value or comparing it to an existing value.
- #
- # @api private
- def method_missing(name, *args)
- question = false
- if name.to_s =~ /\?$/
- question = true
- name = name.to_s.sub(/\?$/,'')
- end
-
- if fact = collection.fact(name)
- if question
- value = fact.value.downcase
- args.each do |arg|
- if arg.to_s.downcase == value
- return true
- end
- end
-
- # If we got this far, there was no match.
- return false
- else
- return fact.value
- end
- else
- # Else, fail like a normal missing method.
- raise NoMethodError, "Could not find fact '%s'" % name
- end
- end
- end
-
# Clears all cached values and removes all facts from memory.
#
# @return [void]
diff --git a/lib/facter/util/netmask.rb b/lib/facter/util/netmask.rb
index 41503c8..c12e3f2 100644
--- a/lib/facter/util/netmask.rb
+++ b/lib/facter/util/netmask.rb
@@ -8,13 +8,13 @@ module Facter::NetMask
when 'Linux'
ops = {
:ifconfig_opts => ['2>/dev/null'],
- :regex => %r{#{Facter.ipaddress}.*?(?:Mask:|netmask)\s*(#{ipregex})}x,
+ :regex => %r{#{Facter.value(:ipaddress)}.*?(?:Mask:|netmask)\s*(#{ipregex})}x,
:munge => nil,
}
when 'SunOS'
ops = {
:ifconfig_opts => ['-a'],
- :regex => %r{\s+ inet \s #{Facter.ipaddress} \s netmask \s (\w{8})}x,
+ :regex => %r{\s+ inet \s #{Facter.value(:ipaddress)} \s netmask \s (\w{8})}x,
:munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') }
}
when 'FreeBSD','NetBSD','OpenBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
diff --git a/spec/unit/facter_spec.rb b/spec/unit/facter_spec.rb
index 42204dd..6817446 100755
--- a/spec/unit/facter_spec.rb
+++ b/spec/unit/facter_spec.rb
@@ -77,22 +77,6 @@ describe Facter do
end
end
- describe "when asked for a fact as an undefined Facter class method" do
- describe "and the collection is already initialized" do
- it "should return the fact's value" do
- Facter.collection
- Facter.ipaddress.should == Facter['ipaddress'].value
- end
- end
-
- describe "and the collection has been just reset" do
- it "should return the fact's value" do
- Facter.reset
- Facter.ipaddress.should == Facter['ipaddress'].value
- end
- end
- end
-
describe "when passed code as a block" do
it "should execute the provided block" do
Facter.add("block_testing") { setcode { "foo" } }
--
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