lib/cistern/formatter/formatador.rb in cistern-2.8.0 vs lib/cistern/formatter/formatador.rb in cistern-2.8.1

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'formatador' module Cistern::Formatter::Formatador def self.call(model) case model @@ -10,28 +12,28 @@ end end def self.model_inspect(model) Thread.current[:formatador] ||= Formatador.new - data = "#{Thread.current[:formatador].indentation}<#{model.class.name}" + data = ["#{Thread.current[:formatador].indentation}<#{model.class.name}"] Thread.current[:formatador].indent do unless model.class.attributes.empty? data << "\n#{Thread.current[:formatador].indentation}" - data << model.class.attributes.map { |attribute, _| "#{attribute}=#{model.send(attribute).inspect}" }.join(",\n#{Thread.current[:formatador].indentation}") + data << model.class.attributes.map { |attribute, _| "#{attribute}=#{model.read_attribute(attribute).inspect}" }.join(",\n#{Thread.current[:formatador].indentation}") end end data << "\n#{Thread.current[:formatador].indentation}>" - data + data.join end def self.collection_inspect(collection) Thread.current[:formatador] ||= Formatador.new - data = "#{Thread.current[:formatador].indentation}<#{collection.class.name}\n" + data = ["#{Thread.current[:formatador].indentation}<#{collection.class.name}\n"] Thread.current[:formatador].indent do unless collection.class.attributes.empty? data << "#{Thread.current[:formatador].indentation}" - data << collection.class.attributes.map { |attribute| "#{attribute}=#{send(attribute).inspect}" }.join(",\n#{Thread.current[:formatador].indentation}") + data << collection.class.attributes.map { |attribute, _| "#{attribute}=#{collection.read_attribute(attribute).inspect}" }.join(",\n#{Thread.current[:formatador].indentation}") data << "\n" end data << "#{Thread.current[:formatador].indentation}[" unless collection.empty? data << "\n" @@ -42,10 +44,10 @@ data << Thread.current[:formatador].indentation end data << "]\n" end data << "#{Thread.current[:formatador].indentation}>" - data + data.join end def table(attributes = nil) Formatador.display_table(map(&:attributes), attributes) end