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

Daniel Pittman daniel at puppetlabs.com
Tue May 10 08:16:48 UTC 2011


The following commit has been merged in the experimental branch:
commit 7438723f6ae13605a48c5db63839a829a19f5127
Merge: a594563919a2342e1ea542f8f18ed187ab9ecad3 0fed94fbbad45388c1f9d2451d946681d80643f8
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Tue Apr 19 10:59:29 2011 -0700

    Merge branch 'bug/2.7.x/6752-allow-action-specific-render-methods'
    
    Fix the conflicts over changes in my previous commit.

diff --combined lib/puppet/interface.rb
index 888e4ec,398d854..5c8ade7
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@@ -62,37 -62,16 +62,35 @@@ class Puppet::Interfac
      end
    end
  
-   attr_accessor :default_format
- 
    def set_default_format(format)
-     self.default_format = format.to_sym
+     Puppet.warning("set_default_format is deprecated (and ineffective); use render_as on your actions instead.")
    end
  
 -  attr_accessor :summary
 +  ########################################################################
 +  # Documentation.  We currently have to rewrite both getters because we share
 +  # the same instance between build-time and the runtime instance.  When that
 +  # splits out this should merge into a module that both the action and face
 +  # include. --daniel 2011-04-17
 +  attr_accessor :summary, :description
    def summary(value = nil)
 -    @summary = value unless value.nil?
 +    self.summary = value unless value.nil?
      @summary
    end
 +  def summary=(value)
 +    value = value.to_s
 +    value =~ /\n/ and
 +      raise ArgumentError, "Face summary should be a single line; put the long text in 'description' instead."
 +
 +    @summary = value
 +  end
 +
 +  def description(value = nil)
 +    self.description = value unless value.nil?
 +    @description
 +  end
 +
  
 +  ########################################################################
    attr_reader :name, :version
  
    def initialize(name, version, &block)
@@@ -102,18 -81,32 +100,17 @@@
  
      @name = Puppet::Interface::FaceCollection.underscorize(name)
      @version = version
-     @default_format = :pson
  
      instance_eval(&block) if block_given?
    end
  
    # Try to find actions defined in other files.
    def load_actions
 -    path = "puppet/face/#{name}"
 -
 -    loaded = []
 -    [path, "#{name}@#{version}/#{path}"].each do |path|
 -      Puppet::Interface.autoloader.search_directories.each do |dir|
 -        fdir = ::File.join(dir, path)
 -        next unless FileTest.directory?(fdir)
 -
 -        Dir.chdir(fdir) do
 -          Dir.glob("*.rb").each do |file|
 -            aname = file.sub(/\.rb/, '')
 -            if loaded.include?(aname)
 -              Puppet.debug "Not loading duplicate action '#{aname}' for '#{name}' from '#{fdir}/#{file}'"
 -              next
 -            end
 -            loaded << aname
 -            Puppet.debug "Loading action '#{aname}' for '#{name}' from '#{fdir}/#{file}'"
 -            require "#{Dir.pwd}/#{aname}"
 -          end
 -        end
 +    Puppet::Interface.autoloader.search_directories.each do |dir|
 +      Dir.glob(File.join(dir, "puppet/face/#{name}", "*.rb")).each do |file|
 +        action = file.sub(dir, '').sub(/^[\\\/]/, '').sub(/\.rb/, '')
 +        Puppet.debug "Loading action '#{action}' for '#{name}' from '#{dir}/#{action}.rb'"
 +        require(action)
        end
      end
    end
@@@ -152,11 -145,11 +149,11 @@@
      end
    end
  
-   def __decorate(type, name, proc)
+   def __add_method(name, proc)
      meta_def(name, &proc)
      method(name).unbind
    end
-   def self.__decorate(type, name, proc)
+   def self.__add_method(name, proc)
      define_method(name, proc)
      instance_method(name)
    end
diff --combined lib/puppet/interface/action.rb
index f6273d1,b438950..23366b4
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@@ -9,7 -9,8 +9,8 @@@ class Puppet::Interface::Actio
      @name    = name.to_sym
      attrs.each do |k, v| send("#{k}=", v) end
  
-     @options = {}
+     @options        = {}
+     @when_rendering = {}
    end
  
    # This is not nice, but it is the easiest way to make us behave like the
@@@ -21,24 -22,66 +22,79 @@@
      return bound_version
    end
  
-   attr_reader :name
    def to_s() "#{@face}##{@name}" end
  
+   attr_reader   :name
    attr_accessor :default
+   def default?
+     !!@default
+   end
+ 
+   attr_accessor :summary
+ 
+ 
+   ########################################################################
+   # Support for rendering formats and all.
+   def when_rendering(type)
+     unless type.is_a? Symbol
+       raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}"
+     end
+     return unless @when_rendering.has_key? type
+     return @when_rendering[type].bind(@face)
+   end
+   def set_rendering_method_for(type, proc)
+     unless proc.is_a? Proc
+       msg = "The second argument to set_rendering_method_for must be a Proc"
+       msg += ", not #{proc.class.name}" unless proc.nil?
+       raise ArgumentError, msg
+     end
+     if proc.arity != 1 then
+       msg = "when_rendering methods take one argument, the result, not "
+       if proc.arity < 0 then
+         msg += "a variable number"
+       else
+         msg += proc.arity.to_s
+       end
+       raise ArgumentError, msg
+     end
+     unless type.is_a? Symbol
+       raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}"
+     end
+     if @when_rendering.has_key? type then
+       raise ArgumentError, "You can't define a rendering method for #{type} twice"
+     end
+     # Now, the ugly bit.  We add the method to our interface object, and
+     # retrieve it, to rotate through the dance of getting a suitable method
+     # object out of the whole process. --daniel 2011-04-18
+     @when_rendering[type] =
+       @face.__send__( :__add_method, __render_method_name_for(type), proc)
+   end
+ 
+   def __render_method_name_for(type)
+     :"#{name}_when_rendering_#{type}"
+   end
+   private :__render_method_name_for
+ 
+ 
+   attr_accessor :render_as
+   def render_as=(value)
+     @render_as = value.to_sym
+   end
+ 
  
 +  ########################################################################
 +  # Documentation stuff, whee!
 +  attr_accessor :summary, :description
 +  def summary=(value)
 +    value = value.to_s
 +    value =~ /\n/ and
 +      raise ArgumentError, "Face summary should be a single line; put the long text in 'description' instead."
 +
 +    @summary = value
 +  end
 +
 +
 +  ########################################################################
    # Initially, this was defined to allow the @action.invoke pattern, which is
    # a very natural way to invoke behaviour given our introspection
    # capabilities.   Heck, our initial plan was to have the faces delegate to
@@@ -169,7 -212,7 +225,7 @@@ WRAPPE
    # Support code for action decoration; see puppet/interface.rb for the gory
    # details of why this is hidden away behind private. --daniel 2011-04-15
    private
-   def __decorate(type, name, proc)
-     @face.__send__ :__decorate, type, name, proc
+   def __add_method(name, proc)
+     @face.__send__ :__add_method, name, proc
    end
  end
diff --combined spec/unit/interface/action_spec.rb
index 5058ffc,07853e7..0eb450e
--- a/spec/unit/interface/action_spec.rb
+++ b/spec/unit/interface/action_spec.rb
@@@ -372,12 -372,12 +372,21 @@@ describe Puppet::Interface::Action d
      end
    end
  
 +  it_should_behave_like "documentation on faces" do
 +    subject do
 +      face = Puppet::Interface.new(:action_documentation, '0.0.1') do
 +        action :documentation do end
 +      end
 +      face.get_action(:documentation)
 +    end
 +  end
++
+   context "#when_rendering" do
+     it "should fail if no type is given when_rendering"
+     it "should accept a when_rendering block"
+     it "should accept multiple when_rendering blocks"
+     it "should fail if when_rendering gets a non-symbol identifier"
+     it "should fail if a second block is given for the same type"
+     it "should return the block if asked"
+   end
  end
diff --combined spec/unit/interface_spec.rb
index 50ae9c7,799b8c4..b4fef03
--- a/spec/unit/interface_spec.rb
+++ b/spec/unit/interface_spec.rb
@@@ -33,7 -33,7 +33,7 @@@ describe Puppet::Interface d
  
    describe "#define" do
      it "should register the face" do
 -      face = subject.define(:face_test_register, '0.0.1')
 +      face  = subject.define(:face_test_register, '0.0.1')
        face.should == subject[:face_test_register, '0.0.1']
      end
  
@@@ -51,16 -51,22 +51,16 @@@
        subject.new(:foo, '1.0.0').should respond_to(:summary=).with(1).arguments
      end
  
 -    it "should set the summary text" do
 -      text = "hello, freddy, my little pal"
 -      subject.define(:face_test_summary, '1.0.0') do
 -        summary text
 -      end
 -      subject[:face_test_summary, '1.0.0'].summary.should == text
 -    end
 -
 -    it "should support mutating the summary" do
 -      text = "hello, freddy, my little pal"
 -      subject.define(:face_test_summary, '1.0.0') do
 -        summary text
 +    # Required documentation methods...
 +    { :summary     => "summary",
 +      :description => "This is the description of the stuff\n\nWhee"
 +    }.each do |attr, value|
 +      it "should support #{attr} in the builder" do
 +        face = subject.new(:builder, '1.0.0') do
 +          self.send(attr, value)
 +        end
 +        face.send(attr).should == value
        end
 -      subject[:face_test_summary, '1.0.0'].summary.should == text
 -      subject[:face_test_summary, '1.0.0'].summary = text + text
 -      subject[:face_test_summary, '1.0.0'].summary.should == text + text
      end
    end
  
@@@ -93,16 -99,6 +93,6 @@@
      subject.new(:me, '0.0.1').to_s.should =~ /\bme\b/
    end
  
-   it "should allow overriding of the default format" do
-     face = subject.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
-     subject.new(:me, '0.0.1').default_format.should == :pson
-   end
- 
    # Why?
    it "should create a class-level autoloader" do
      subject.autoloader.should be_instance_of(Puppet::Util::Autoload)
@@@ -198,10 -194,4 +188,10 @@@
        end
      end
    end
 +
 +  it_should_behave_like "documentation on faces" do
 +    subject do
 +      Puppet::Interface.new(:face_documentation, '0.0.1')
 +    end
 +  end
  end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list