summaryrefslogtreecommitdiffstats
path: root/lib/puppet/resource.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/resource.rb')
-rw-r--r--lib/puppet/resource.rb29
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index e832804f5..a71675e11 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