Class: GemWhy::Formatters::TreeFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/gem_why/formatters/tree_formatter.rb

Overview

Formats tree visualization output

Instance Attribute Summary collapse

Attributes inherited from BaseFormatter

#command

Instance Method Summary collapse

Constructor Details

#initialize(command, tree_builder) ⇒ TreeFormatter

Returns a new instance of TreeFormatter.



11
12
13
14
# File 'lib/gem_why/formatters/tree_formatter.rb', line 11

def initialize(command, tree_builder)
  super(command)
  @tree_builder = tree_builder
end

Instance Attribute Details

#tree_builderObject (readonly)

Returns the value of attribute tree_builder.



9
10
11
# File 'lib/gem_why/formatters/tree_formatter.rb', line 9

def tree_builder
  @tree_builder
end

Instance Method Details

#format(gem_name, chains) ⇒ void

This method returns an undefined value.

Formats and displays dependency tree

Parameters:

  • gem_name (String)

    the target gem name

  • chains (Array<Array<Hash>>)

    the dependency chains



20
21
22
23
24
25
26
# File 'lib/gem_why/formatters/tree_formatter.rb', line 20

def format(gem_name, chains)
  return say "No gems depend on #{colorize(gem_name, :yellow)}" if chains.empty?

  say "Dependency tree for #{colorize(gem_name, :cyan)}:\n\n"
  print_dependency_tree(chains, gem_name)
  print_tree_summary(chains, gem_name)
end