This causes failing tests.  I thought it would be really easy to fix
the tests, but it turns out that the ability to sort symbols comes in
the preinit section of application run when we load Facter and hit the
code that adds the <=> method for symbols in
lib/facter/util/plist/generator.rb

I'm going to add Symbol sorting to Puppet's monkey patching so it's
less surprising where it's coming from.  I've also got a test for the
changes here.  I'll send the patch shortly.

On Thu, Feb 3, 2011 at 4:14 PM, Nan Liu <[email protected]> wrote:
> Revised patch based on feedback to first patch. Fixed:
> Add trailing comma for last attribute
> Cleaner logic to align =>
> Ensure is first attribute is ensure
> Sort remaining attribute
> Use 2 spaces instead of 4
>
> Thanks,
>
> Nan
>
> ---
>  lib/puppet/resource.rb |   29 ++++++++++++++++++++---------
>  1 files changed, 20 insertions(+), 9 deletions(-)
>
> diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
> index e832804..a71675e 100644
> --- a/lib/puppet/resource.rb
> +++ b/lib/puppet/resource.rb
> @@ -255,15 +255,26 @@ class Puppet::Resource
>
>   # Convert our resource to Puppet code.
>   def to_manifest
> -    "%s { '%s':\n%s\n}" % [self.type.to_s.downcase, self.title,
> -      @parameters.collect { |p, v|
> -        if v.is_a? Array
> -          "    #{p} => [\'#{v.join("','")}\']"
> -        else
> -          "    #{p} => \'#{v}\'"
> -        end
> -      }.join(",\n")
> -      ]
> +    # Collect list of attributes to align => and move ensure first
> +    attr = @parameters.keys
> +    attr_max = attr.inject(0) { |max,k| k.to_s.length > max ? k.to_s.length 
> : max }
> +
> +    attr.sort!
> +    if attr.first != :ensure  && attr.include?(:ensure)
> +      attr.delete(:ensure)
> +      attr.unshift(:ensure)
> +    end
> +
> +    attributes = attr.collect { |k|
> +      v = @parameters[k]
> +      if v.is_a? Array
> +        "  %-#{attr_max}s => %s,\n" % [ k, "[\'#{v.join("', '")}\']" ]
> +      else
> +        "  %-#{attr_max}s => %s,\n" % [ k, "\'#{v}\'" ]
> +      end
> +    }
> +
> +    "%s { '%s':\n%s}" % [self.type.to_s.downcase, self.title, attributes]
>   end
>
>   def to_ref
> --
> 1.7.3.5
>
> --
> 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.
>
>

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