On Aug 19, 2008, at 11:53 PM, AJ Christensen wrote:

>
> I hadn't tested .sort.each on a setup with more than one node, and  
> Puppet::Node::Facts obviously doesn't have an <=> method.
>
> This implements a simple string sort based on the node name
>
> Signed-off-by: AJ Christensen <[EMAIL PROTECTED]>
> ---
> ext/puppetlast |    2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/ext/puppetlast b/ext/puppetlast
> index d9b698c..e52529d 100755
> --- a/ext/puppetlast
> +++ b/ext/puppetlast
> @@ -10,6 +10,6 @@ Puppet.parse_config
> Puppet[:name] = "puppetmasterd"
> Puppet::Node::Facts.terminus_class = :yaml
>
> -Puppet::Node::Facts.search("*").sort.each do |node|
> +Puppet::Node::Facts.search("*").sort { |a,b| a.name <=>  
> b.name }.each do |node|
>   puts "#{node.name} #{node.expired? ? 'cached expired, ' :  
> ''}checked in #{((Time.now - node.values[:_timestamp]) / 60).floor}  
> minutes ago"
> end

This is obviously fine, but another option is to add the <=> method to  
the Facts class:

diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb
index 8ee90b4..035364c 100755
--- a/lib/puppet/node/facts.rb
+++ b/lib/puppet/node/facts.rb
@@ -7,6 +7,7 @@ class Puppet::Node::Facts
      # Set up indirection, so that nodes can be looked for in
      # the node sources.
      extend Puppet::Indirector
+    include Enumerable

      # We want to expire any cached nodes if the facts are saved.
      module NodeExpirer
@@ -21,6 +22,10 @@ class Puppet::Node::Facts

      attr_accessor :name, :values

+    def <=>(other)
+        name <=> other.name
+    end
+
      def initialize(name, values = {})
          @name = name
          @values = values

-- 
Brand's Shortcut:
     The only way to predict the future is to make sure it stays
     exactly the same as the present.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


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