diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 02:59:39 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-03 02:59:39 +0000 |
| commit | a11505035c62ce850cd49648bda1f25c811674c4 (patch) | |
| tree | ab0a6d93e8c775b4dc1b30d65048cf95dcfdaa24 | |
| parent | f797487ee2672c7e91b74c57d839cd52102a16d1 (diff) | |
Adding pre- and post-hooks, as requested in #233.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1541 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | lib/puppet/util/classgen.rb | 8 | ||||
| -rwxr-xr-x | test/util/classgen.rb | 26 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb index d7622cf93..9c7e571f6 100644 --- a/lib/puppet/util/classgen.rb +++ b/lib/puppet/util/classgen.rb @@ -65,6 +65,10 @@ module Puppet::Util::ClassGen end end + if klass.respond_to? :preinit + klass.preinit + end + block ||= options[:block] # Evaluate the passed block if there is one. This should usually @@ -73,6 +77,10 @@ module Puppet::Util::ClassGen klass.class_eval(&block) end + if klass.respond_to? :postinit + klass.postinit + end + # If we were told to stick it in a hash, then do so if hash = options[:hash] if hash.include? name and ! options[:overwrite] diff --git a/test/util/classgen.rb b/test/util/classgen.rb index 2fdcf5d6a..825a98f3c 100755 --- a/test/util/classgen.rb +++ b/test/util/classgen.rb @@ -12,6 +12,9 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase include TestPuppet class FakeBase + class << self + attr_accessor :name + end end class GenTest @@ -38,6 +41,29 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase assert(hash.include?(klass.name), "Class did not get added to hash") end + + # Make sure we call a preinithook, if there is one. + def test_inithooks + newclass = Class.new(FakeBase) do + class << self + attr_accessor :preinited, :postinited + end + def self.preinit + self.preinited = true + end + def self.postinit + self.postinited = true + end + end + + klass = nil + assert_nothing_raised { + klass = GenTest.genclass(:yayness, :parent => newclass) + } + + assert(klass.preinited, "prehook did not get called") + assert(klass.postinited, "posthook did not get called") + end end # $Id$ |
