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.