[Pkg-puppet-devel] [facter] 162/352: (maint) Reuse fact creation logic in collection
Stig Sandbeck Mathisen
ssm at debian.org
Sun Apr 6 22:21:42 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 6f7406215b93057afb882b3157357985a3f7fb5c
Author: Adrien Thebo <git at somethingsinistral.net>
Date: Wed Jan 15 16:33:02 2014 -0800
(maint) Reuse fact creation logic in collection
---
lib/facter/util/collection.rb | 34 +++++++++++++++++-----------------
spec/unit/util/collection_spec.rb | 5 +++--
2 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/lib/facter/util/collection.rb b/lib/facter/util/collection.rb
index ea5b95d..abf83b1 100644
--- a/lib/facter/util/collection.rb
+++ b/lib/facter/util/collection.rb
@@ -26,14 +26,7 @@ class Facter::Util::Collection
#
# @return [Facter::Util::Fact] The fact that was defined
def define_fact(name, options = {}, &block)
- name = canonicalize(name)
-
- fact = @facts[name]
-
- if fact.nil?
- fact = Facter::Util::Fact.new(name, options)
- @facts[name] = fact
- end
+ fact = create_or_return_fact(name, options)
if block_given?
fact.instance_eval(&block)
@@ -52,15 +45,7 @@ class Facter::Util::Collection
#
# @return [Facter::Util::Fact] The fact that was defined
def add(name, options = {}, &block)
- name = canonicalize(name)
-
- unless fact = @facts[name]
- fact = Facter::Util::Fact.new(name)
-
- @facts[name] = fact
- end
-
- fact.extract_ldapname_option!(options)
+ fact = create_or_return_fact(name, options)
if block_given?
resolve = fact.add(&block)
@@ -157,6 +142,21 @@ class Facter::Util::Collection
private
+ def create_or_return_fact(name, options)
+ name = canonicalize(name)
+
+ fact = @facts[name]
+
+ if fact.nil?
+ fact = Facter::Util::Fact.new(name, options)
+ @facts[name] = fact
+ else
+ fact.extract_ldapname_option!(options)
+ end
+
+ fact
+ end
+
def canonicalize(name)
name.to_s.downcase.to_sym
end
diff --git a/spec/unit/util/collection_spec.rb b/spec/unit/util/collection_spec.rb
index c77f429..4414978 100755
--- a/spec/unit/util/collection_spec.rb
+++ b/spec/unit/util/collection_spec.rb
@@ -32,7 +32,7 @@ describe Facter::Util::Collection do
it "should set appropriate options on the resolution instance" do
fact = Facter::Util::Fact.new(:myname)
- Facter::Util::Fact.expects(:new).with(:myname).returns fact
+ Facter::Util::Fact.expects(:new).with(:myname, {:timeout => 'myval'}).returns fact
resolve = Facter::Util::Resolution.new(:myname) {}
fact.expects(:add).returns resolve
@@ -46,7 +46,8 @@ describe Facter::Util::Collection do
describe "and a block is provided" do
it "should use the block to add a resolution to the fact" do
- fact = mock 'fact', :extract_ldapname_option! => nil
+ fact = mock 'fact'
+ fact.stubs(:extract_ldapname_option!)
Facter::Util::Fact.expects(:new).returns fact
fact.expects(:add)
--
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