Class: YARD::CLI::Graph

Inherits:
Command show all
Defined in:
lib/yard/cli/graph.rb

Overview

A command-line utility to generate Graphviz graphs from a set of objects

See Also:

Since:

  • 0.6.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#common_options, #load_script, #parse_options, run

Constructor Details

#initializeGraph

Creates a new instance of the command-line utility

Since:

  • 0.6.0



18
19
20
21
22
# File 'lib/yard/cli/graph.rb', line 18

def initialize
  super
  @serializer = YARD::Serializers::StdoutSerializer.new
  @options = SymbolHash[:format => :dot]
end

Instance Attribute Details

#objectsObject (readonly)

The set of objects to include in the graph.

Since:

  • 0.6.0



15
16
17
# File 'lib/yard/cli/graph.rb', line 15

def objects
  @objects
end

#optionsObject (readonly)

The options parsed out of the commandline. Default options are:

:format => :dot

Since:

  • 0.6.0



12
13
14
# File 'lib/yard/cli/graph.rb', line 12

def options
  @options
end

Instance Method Details

#descriptionObject

Since:

  • 0.6.0



24
25
26
# File 'lib/yard/cli/graph.rb', line 24

def description
  "Graphs class diagram using Graphviz"
end

#run(*args) ⇒ Object

Runs the command-line utility.

Examples:

grapher = Graph.new
grapher.run('--private')

Since:

  • 0.6.0



34
35
36
37
38
39
40
41
42
# File 'lib/yard/cli/graph.rb', line 34

def run(*args)
  Registry.load
  optparse(*args)

  contents = objects.map {|o| o.format(options) }.join("\n")
  Templates::Engine.render(:format => :dot, :type => :layout,
    :verifier => @verifier, :serializer => @serializer,
    :contents => contents)
end