Also Nigel mentioned having ensure as the first attribute would be
idea and I wasn't sure the best way to add that feature. Comparing
attr.to_s="ensure" and then reconstructing the string seems like the
wrong way altogether since the code looked dirty and ugly.

Thanks,

Nan

On Tue, Feb 1, 2011 at 6:54 PM, Nan Liu <[email protected]> wrote:
> Includes following changes:
>
> Fixed puppet resource so it have trailing , for last attribute
> Added logic to align =>
> Sort attribute by name
> Use 2 spaces instead of 4
>
> ---
>  lib/puppet/resource.rb |   11 ++++++++---
>  1 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
> index e832804..0419cdd 100644
> --- a/lib/puppet/resource.rb
> +++ b/lib/puppet/resource.rb
> @@ -255,14 +255,19 @@ class Puppet::Resource
>
>   # Convert our resource to Puppet code.
>   def to_manifest
> +    # Collect list of attributes to align =>
> +    attributes = @parameters.collect { |attr, val| attr }
> +    attr_max = attributes.max{ |a, b| a.to_s.length <=> b.to_s.length 
> }.to_s.length
> +
>     "%s { '%s':\n%s\n}" % [self.type.to_s.downcase, self.title,
>       @parameters.collect { |p, v|
> +        space = " " * (attr_max-p.to_s.length)
>         if v.is_a? Array
> -          "    #{p} => [\'#{v.join("','")}\']"
> +          "  #{p}#{space} => [\'#{v.join("','")}\']"
>         else
> -          "    #{p} => \'#{v}\'"
> +          "  #{p}#{space} => \'#{v}\'"
>         end
> -      }.join(",\n")
> +      }.sort.join(",\n") + ","
>       ]
>   end
>
> --
> 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.

Reply via email to