[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Pieter van de Bruggen pieter at puppetlabs.com
Tue May 10 08:08:19 UTC 2011


The following commit has been merged in the experimental branch:
commit 78371a739bcf1b1d76496e9038fa4b076a27032f
Author: Pieter van de Bruggen <pieter at puppetlabs.com>
Date:   Thu Mar 24 09:25:33 2011 -0700

    (#6770) Refactor Puppet::Interface#initialize.
    
    P::I#initialize now takes a name and a version (and an optional block).  The
    options hash has been removed, though it may be reintroduced if a legitimate
    use case can be made for it (so far, it's only been used for the version
    number).
    
    Reviewed-By: Jacob Helwig

diff --git a/README.markdown b/README.markdown
index 5f720db..29ff414 100644
--- a/README.markdown
+++ b/README.markdown
@@ -86,7 +86,7 @@ Or use IRB to do the same thing:
     => true
     >> interface = Puppet::Interface[:facts, '1.0.0']
     => #<Puppet::Interface::Facts:0x1024a1390 @format=:yaml>
-    >> facts = interface.find("myhost"); nil
+    >> facts = interface.find("myhost")
 
 Like I said, a prototype, but I'd love it if people would play it with some and make some recommendations.
 
@@ -111,3 +111,5 @@ Like most parts of Puppet, these are easy to extend.  Just drop a new action int
     $
 
 Notice that this gets loaded automatically when you try to use it.  So, if you have a simple command you've written, such as for cleaning up nodes or diffing catalogs, you an port it to this framework and it should fit cleanly.
+
+Also note that interfaces are versioned.  These version numbers are interpreted according to Semantic Versioning (http://semver.org).
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 64f1bfe..27cbb75 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -30,15 +30,17 @@ class Puppet::Interface
       Puppet::Interface::InterfaceCollection.register(instance)
     end
 
-    def define(name, version, &blk)
+    def define(name, version, &block)
       if interface?(name, version)
         interface = Puppet::Interface::InterfaceCollection[name, version]
-        interface.instance_eval(&blk) if blk
       else
-        interface = self.new(name, :version => version, &blk)
+        interface = self.new(name, version)
         Puppet::Interface::InterfaceCollection.register(interface)
         interface.load_actions
       end
+
+      interface.instance_eval(&block) if block_given?
+
       return interface
     end
 
@@ -54,22 +56,17 @@ class Puppet::Interface
   attr_accessor :type, :verb, :version, :arguments, :options
   attr_reader :name
 
-  def initialize(name, options = {}, &block)
-    unless options[:version]
-      raise ArgumentError, "Interface #{name} declared without version!"
-    end
-
+  def initialize(name, version, &block)
     @name = Puppet::Interface::InterfaceCollection.underscorize(name)
-
+    @version = version
     @default_format = :pson
-    options.each { |opt, val| send(opt.to_s + "=", val) }
 
-    instance_eval(&block) if block
+    instance_eval(&block) if block_given?
   end
 
   # Try to find actions defined in other files.
   def load_actions
-    path = "puppet/interface/#{name}"
+    path = "puppet/interface/v#{version}/#{name}"
 
     loaded = []
     Puppet::Interface.autoloader.search_directories.each do |dir|
@@ -92,6 +89,6 @@ class Puppet::Interface
   end
 
   def to_s
-    "Puppet::Interface(#{name}, :version => #{version.inspect})"
+    "Puppet::Interface[#{name.inspect}, #{version.inspect}]"
   end
 end
diff --git a/lib/puppet/interface/interface_collection.rb b/lib/puppet/interface/interface_collection.rb
index d626c4f..51b7534 100644
--- a/lib/puppet/interface/interface_collection.rb
+++ b/lib/puppet/interface/interface_collection.rb
@@ -9,7 +9,7 @@ module Puppet::Interface::InterfaceCollection
       $LOAD_PATH.each do |dir|
         next unless FileTest.directory?(dir)
         Dir.chdir(dir) do
-          Dir.glob("puppet/interface/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file|
+          Dir.glob("puppet/interface/v*/*.rb").collect { |f| f.sub(/\.rb/, '') }.each do |file|
             iname = file.sub(/\.rb/, '')
             begin
               require iname
diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb
index 2c2f3b1..27e817f 100644
--- a/spec/unit/interface/action_builder_spec.rb
+++ b/spec/unit/interface/action_builder_spec.rb
@@ -13,7 +13,7 @@ describe Puppet::Interface::ActionBuilder do
     end
 
     it "should define a method on the interface which invokes the action" do
-      interface = Puppet::Interface.new(:action_builder_test_interface, :version => '0.0.1')
+      interface = Puppet::Interface.new(:action_builder_test_interface, '0.0.1')
       action = Puppet::Interface::ActionBuilder.build(interface, :foo) do
         invoke do
           "invoked the method"
diff --git a/spec/unit/interface/action_spec.rb b/spec/unit/interface/action_spec.rb
index 246ae96..292caab 100644
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@ -24,7 +24,7 @@ describe Puppet::Interface::Action do
 
   describe "when invoking" do
     it "should be able to call other actions on the same object" do
-      interface = Puppet::Interface.new(:my_interface, :version => '0.0.1') do
+      interface = Puppet::Interface.new(:my_interface, '0.0.1') do
         action(:foo) do
           invoke { 25 }
         end
@@ -56,7 +56,7 @@ describe Puppet::Interface::Action do
         end
       end
 
-      interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, :version => '0.0.1') do
+      interface = Puppet::Interface::MyInterfaceBaseClass.new(:my_inherited_interface, '0.0.1') do
         action(:baz) do
           invoke { "the value of foo in baz is '#{foo}'" }
         end
diff --git a/spec/unit/interface/indirector_spec.rb b/spec/unit/interface/indirector_spec.rb
index b14058e..4b2beae 100644
--- a/spec/unit/interface/indirector_spec.rb
+++ b/spec/unit/interface/indirector_spec.rb
@@ -5,7 +5,7 @@ require 'puppet/interface/indirector'
 
 describe Puppet::Interface::Indirector do
   before do
-    @instance = Puppet::Interface::Indirector.new(:test, :version => '0.0.1')
+    @instance = Puppet::Interface::Indirector.new(:test, '0.0.1')
 
     @indirection = stub 'indirection', :name => :stub_indirection
 
@@ -24,7 +24,7 @@ describe Puppet::Interface::Indirector do
     it "should be able to determine its indirection" do
       # Loading actions here an get, um, complicated
       Puppet::Interface.stubs(:load_actions)
-      Puppet::Interface::Indirector.new(:catalog, :version => '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection)
+      Puppet::Interface::Indirector.new(:catalog, '0.0.1').indirection.should equal(Puppet::Resource::Catalog.indirection)
     end
   end
 
diff --git a/spec/unit/interface/interface_collection_spec.rb b/spec/unit/interface/interface_collection_spec.rb
index 193d31b..a404d85 100644
--- a/spec/unit/interface/interface_collection_spec.rb
+++ b/spec/unit/interface/interface_collection_spec.rb
@@ -67,7 +67,7 @@ describe Puppet::Interface::InterfaceCollection do
 
   describe "::register" do
     it "should store the interface by name" do
-      interface = Puppet::Interface.new(:my_interface, :version => '0.0.1')
+      interface = Puppet::Interface.new(:my_interface, '0.0.1')
       subject.register(interface)
       subject.instance_variable_get("@interfaces").should == {:my_interface => {'0.0.1' => interface}}
     end
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb
index 520060c..060a71f 100755
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@ -15,29 +15,29 @@ describe Puppet::Interface do
     Puppet::Interface::InterfaceCollection.instance_variable_set("@interfaces", @interfaces)
   end
 
-  describe "#interface" do
+  describe "#define" do
     it "should register the interface" do
-      interface = Puppet::Interface[:interface_test_register, '0.0.1']
+      interface = Puppet::Interface.define(:interface_test_register, '0.0.1')
       interface.should == Puppet::Interface[:interface_test_register, '0.0.1']
     end
 
     it "should load actions" do
       Puppet::Interface.any_instance.expects(:load_actions)
-      Puppet::Interface[:interface_test_load_actions, '0.0.1']
+      Puppet::Interface.define(:interface_test_load_actions, '0.0.1')
     end
 
     it "should require a version number" do
-      proc { Puppet::Interface[:no_version] }.should raise_error(ArgumentError)
+      proc { Puppet::Interface.define(:no_version) }.should raise_error(ArgumentError)
     end
   end
 
   describe "#initialize" do
     it "should require a version number" do
-      proc { Puppet::Interface.new(:no_version) }.should raise_error(/declared without version/)
+      proc { Puppet::Interface.new(:no_version) }.should raise_error(ArgumentError)
     end
 
     it "should instance-eval any provided block" do
-      face = Puppet::Interface.new(:interface_test_block, :version => '0.0.1') do
+      face = Puppet::Interface.new(:interface_test_block,'0.0.1') do
         action(:something) do
           invoke { "foo" }
         end
@@ -48,21 +48,21 @@ describe Puppet::Interface do
   end
 
   it "should have a name" do
-    Puppet::Interface.new(:me, :version => '0.0.1').name.should == :me
+    Puppet::Interface.new(:me,'0.0.1').name.should == :me
   end
 
   it "should stringify with its own name" do
-    Puppet::Interface.new(:me, :version => '0.0.1').to_s.should =~ /\bme\b/
+    Puppet::Interface.new(:me,'0.0.1').to_s.should =~ /\bme\b/
   end
 
   it "should allow overriding of the default format" do
-    face = Puppet::Interface.new(:me, :version => '0.0.1')
+    face = Puppet::Interface.new(:me,'0.0.1')
     face.set_default_format :foo
     face.default_format.should == :foo
   end
 
   it "should default to :pson for its format" do
-    Puppet::Interface.new(:me, :version => '0.0.1').default_format.should == :pson
+    Puppet::Interface.new(:me, '0.0.1').default_format.should == :pson
   end
 
   # Why?
@@ -70,10 +70,6 @@ describe Puppet::Interface do
     Puppet::Interface.autoloader.should be_instance_of(Puppet::Util::Autoload)
   end
 
-  it "should set any provided options" do
-    Puppet::Interface.new(:me, :version => 1, :verb => "foo").verb.should == "foo"
-  end
-
   it "should try to require interfaces that are not known" do
     Puppet::Interface::InterfaceCollection.expects(:require).with "puppet/interface/v0.0.1/foo"
     Puppet::Interface[:foo, '0.0.1']

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list