[Pkg-puppet-devel] [facter] 246/352: (FACT-239) Implement Facter.define_fact

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:50 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 c5d4654a2846080143a2c0bf0886b9567a36ac51
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Mon Feb 3 10:04:28 2014 -0800

    (FACT-239) Implement Facter.define_fact
    
    This allows calling classes to create or reopen a fact by itself,
    without interacting with resolutions.
---
 lib/facter.rb            | 13 +++++++++++++
 spec/unit/facter_spec.rb | 10 ++++++++++
 2 files changed, 23 insertions(+)

diff --git a/lib/facter.rb b/lib/facter.rb
index e85c99b..4e102a8 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -128,6 +128,19 @@ module Facter
     collection.to_hash
   end
 
+  # Define a new fact or extend an existing fact.
+  #
+  # @param name [Symbol] The name of the fact to define
+  # @param options [Hash] A hash of options to set on the fact
+  #
+  # @return [Facter::Util::Fact] The fact that was defined
+  #
+  # @api public
+  # @see {Facter::Util::Collection#define_fact}
+  def self.define_fact(name, options = {}, &block)
+    collection.define_fact(name, options, &block)
+  end
+
   # Adds a {Facter::Util::Resolution resolution} mechanism for a named
   # fact. This does not distinguish between adding a new fact and adding
   # a new way to resolve a fact.
diff --git a/spec/unit/facter_spec.rb b/spec/unit/facter_spec.rb
index 9cf03f8..62870f0 100755
--- a/spec/unit/facter_spec.rb
+++ b/spec/unit/facter_spec.rb
@@ -49,6 +49,16 @@ describe Facter do
       Facter.each
     end
 
+    it "delegates the :add method to the collection" do
+      Facter.collection.expects(:add).with("factname", {})
+      Facter.add("factname")
+    end
+
+    it "delegates the :define_fact method to the collection" do
+      Facter.collection.expects(:define_fact).with("factname", {})
+      Facter.define_fact("factname")
+    end
+
     it "loads all facts when calling :each" do
       Facter.collection.expects(:load_all)
       Facter.collection.stubs(:each)

-- 
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