When we first touch a Face, we load all the available Actions from disk.

Given they define themselves against a specific version of a Face, they are
automatically available tied to the correct version; this makes it trivially
possible to locate those on demand and return them.

Now, we have the ability to find and, consequently, invoke Actions on older
versions of Faces.  We don't load enough context, though: the older face will
only have external Actions defined, not anything core.

Reviewed-By: Pieter van de Bruggen <[email protected]>
---
 lib/puppet/interface/face_collection.rb     |   13 ++++++++++---
 spec/lib/puppet/face/huzzah/obsolete.rb     |    6 ++++++
 spec/unit/interface/face_collection_spec.rb |   15 +++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 spec/lib/puppet/face/huzzah/obsolete.rb

diff --git a/lib/puppet/interface/face_collection.rb 
b/lib/puppet/interface/face_collection.rb
index ddc66f5..868997b 100644
--- a/lib/puppet/interface/face_collection.rb
+++ b/lib/puppet/interface/face_collection.rb
@@ -20,12 +20,19 @@ module Puppet::Interface::FaceCollection
     get_face(name, version) or load_face(name, version)
   end
 
-  def self.get_action_for_face(face_name, action_name, version)
+  def self.get_action_for_face(name, action_name, version)
+    name = underscorize(name)
+
     # If the version they request specifically doesn't exist, don't search
     # elsewhere.  Usually this will start from :current and all...
-    return nil unless face = self[face_name, version]
+    return nil unless face = self[name, version]
     unless action = face.get_action(action_name)
-      # ...we need to search for it bound to an o{lder,ther} version.
+      # ...we need to search for it bound to an o{lder,ther} version.  Since
+      # we load all actions when the face is first references, this will be in
+      # memory in the known set of versions of the face.
+      (@faces[name].keys - [ :current ]).sort.reverse.each do |version|
+        break if action = @faces[name][version].get_action(action_name)
+      end
     end
 
     return action
diff --git a/spec/lib/puppet/face/huzzah/obsolete.rb 
b/spec/lib/puppet/face/huzzah/obsolete.rb
new file mode 100644
index 0000000..1f717ea
--- /dev/null
+++ b/spec/lib/puppet/face/huzzah/obsolete.rb
@@ -0,0 +1,6 @@
+Puppet::Face.define(:huzzah, '1.0.0') do
+  action :obsolete do
+    summary "This is an action on version 1.0.0 of the face"
+    when_invoked do |options| options end
+  end
+end
diff --git a/spec/unit/interface/face_collection_spec.rb 
b/spec/unit/interface/face_collection_spec.rb
index 98887a7..8f9c349 100755
--- a/spec/unit/interface/face_collection_spec.rb
+++ b/spec/unit/interface/face_collection_spec.rb
@@ -97,6 +97,21 @@ describe Puppet::Interface::FaceCollection do
     end
   end
 
+  describe "::get_action_for_face" do
+    it "should return an action on the current face" do
+      Puppet::Face::FaceCollection.get_action_for_face(:huzzah, :bar, 
:current).
+        should be_an_instance_of Puppet::Interface::Action
+    end
+
+    it "should return an action on an older version of a face" do
+      action = Puppet::Face::FaceCollection.
+        get_action_for_face(:huzzah, :obsolete, :current)
+
+      action.should be_an_instance_of Puppet::Interface::Action
+      action.face.version.should == SemVer.new('1.0.0')
+    end
+  end
+
   describe "::register" do
     it "should store the face by name" do
       face = Puppet::Face.new(:my_face, '0.0.1')
-- 
1.7.6

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to