diff options
| author | Matt Robinson <matt@puppetlabs.com> | 2011-02-28 17:11:14 -0800 |
|---|---|---|
| committer | Matt Robinson <matt@puppetlabs.com> | 2011-02-28 17:11:14 -0800 |
| commit | 395831ef58f1ea323919a0a87093919e3526da6c (patch) | |
| tree | 135a3081e806a929420ae9e13b436ef49dd81fc3 /lib | |
| parent | 43c79b744d0af0c5a1221addc74cc36eb68071a6 (diff) | |
| parent | 422399b47764e29055974ff5bad5dfcb982a8b74 (diff) | |
| download | puppet-395831ef58f1ea323919a0a87093919e3526da6c.tar.gz puppet-395831ef58f1ea323919a0a87093919e3526da6c.tar.xz puppet-395831ef58f1ea323919a0a87093919e3526da6c.zip | |
Merge branch 'ticket/2.6.next/5466' into 2.6.next
* ticket/2.6.next/5466:
(#5466) Write specs for output of puppet resource
(#5466) Monkey patch Symbol so that you can sort them
(#5466) Fixed puppet resource bug with trailing ,
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/resource.rb | 29 | ||||
| -rw-r--r-- | lib/puppet/util/monkey_patches.rb | 3 |
2 files changed, 23 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 diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index 85854a04c..16384855a 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -21,6 +21,9 @@ class Symbol z.emit("!ruby/sym ") to_s.to_zaml(z) end + def <=> (other) + self.to_s <=> other.to_s + end end [Object, Exception, Integer, Struct, Date, Time, Range, Regexp, Hash, Array, Float, String, FalseClass, TrueClass, Symbol, NilClass, Class].each { |cls| |
