Module: PoolParty::PrettyPrinter
- Included in:
- Cloud::Cloud, PoolParty::Pool::Pool
- Defined in:
- lib/poolparty/modules/pretty_printer.rb
Instance Method Summary collapse
- #pretty_name(pre, o) ⇒ Object
-
#pretty_options(pre, o) ⇒ Object
Gather options on the object Do not print if the option is nil or empty.
- #pretty_print(pre = "\t") ⇒ Object
Instance Method Details
#pretty_name(pre, o) ⇒ Object
35 36 37 |
# File 'lib/poolparty/modules/pretty_printer.rb', line 35 def pretty_name(pre, o) "#{pre}#{o.class.to_s.top_level_class.capitalize}: #{o.name if o.respond_to?(:name)}" end |
#pretty_options(pre, o) ⇒ Object
Gather options on the object Do not print if the option is nil or empty. Also, don’t show the option if the option is empty or the default option on the cloud
26 27 28 29 30 31 32 33 |
# File 'lib/poolparty/modules/pretty_printer.rb', line 26 def (pre, o) return "" unless o.respond_to?(:options) = (o.respond_to?(:parent) && o.parent && o.parent.respond_to?(:options)) ? (o..delete_if {|k,v| o.parent..has_key?(k) && o.parent.[k] == o.[k] && !o.[k].nil? } ) : o. = .map {|k,v| [k, o.send(k.to_sym).to_s] }.inject({}) { |r,e| r[e[0]] = e[1] unless o.class.[e[0]] == e[1] || e[1].nil? || e[1].empty?; r } .flush_out("#{pre}\t") end |
#pretty_print(pre = "\t") ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/poolparty/modules/pretty_printer.rb', line 4 def pretty_print(pre="\t") pre = "\t" unless pre.is_a?(String) returning Array.new do |out| out << pretty_name(pre, self) out << (pre, self) if self.respond_to?(:clouds) clouds.each do |name, cl| out << pretty_name(pre*2, cl) out << (pre*2, cl) #cl.pretty_print("#{pre}\t") end end if self.respond_to?(:plugins) out << "#{pre}\t\tPlugins" out << "#{pre}\t\t" + plugins.map {|a| a}.join("\n") end end.join("\n") end |