Class: Bundler::PubGrub::FailureWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ FailureWriter

Returns a new instance of FailureWriter.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb', line 3

def initialize(root)
  @root = root

  # { Incompatibility => Integer }
  @derivations = {}

  # [ [ String, Integer or nil ] ]
  @lines = []

  # { Incompatibility => Integer }
  @line_numbers = {}

  count_derivations(root)
end

Instance Method Details

#writeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb', line 18

def write
  return @root.to_s unless @root.conflict?

  visit(@root)

  padding = @line_numbers.empty? ? 0 : "(#{@line_numbers.values.last}) ".length

  @lines.map do |message, number|
    next "" if message.empty?

    lead = number ? "(#{number}) " : ""
    lead = lead.ljust(padding)
    message = message.gsub("\n", "\n" + " " * (padding + 2))
    "#{lead}#{message}"
  end.join("\n")
end