Class: Jinx::Resource::DetailPrinter
Overview
A DetailPrinter formats a domain object value for printing using #to_s the first time the object is encountered and a ReferencePrinter on the object subsequently.
Instance Method Summary collapse
-
#initialize(base, visited = Set.new, &selector) ⇒ DetailPrinter
constructor
Creates a DetailPrinter on the base object.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize(base, visited = Set.new, &selector) ⇒ DetailPrinter
Creates a DetailPrinter on the base object.
769 770 771 772 773 |
# File 'lib/jinx/resource.rb', line 769 def initialize(base, visited=Set.new, &selector) @base = base @visited = visited << base @selector = selector || Proc.new { |ref| ref.class.printable_attributes } end |
Instance Method Details
#pretty_print(q) ⇒ Object
775 776 777 778 779 780 781 782 783 784 785 786 787 |
# File 'lib/jinx/resource.rb', line 775 def pretty_print(q) q.text(@base.qp) # pretty-print the standard attribute values pas = @selector.call(@base) content = @base.printable_content(pas) do |ref| if @visited.include?(ref) then ReferencePrinter.new(ref) else DetailPrinter.new(ref, @visited) { |ref| @selector.call(ref) } end end q.pp_hash(content) end |