Class: YARD::CLI::Graph

Inherits:
YardoptsCommand 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

Constant Summary

Constants inherited from YardoptsCommand

YardoptsCommand::DEFAULT_YARDOPTS_FILE

Instance Attribute Summary collapse

Attributes inherited from YardoptsCommand

#options_file, #use_document_file, #use_yardopts_file

Instance Method Summary collapse

Methods inherited from YardoptsCommand

#parse_arguments

Methods inherited from Command

run

Constructor Details

#initializeGraph

Creates a new instance of the command-line utility

Since:

  • 0.6.0



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

def initialize
  super
  @use_document_file = false
  @options = GraphOptions.new
  options.reset_defaults
  options.serializer = YARD::Serializers::StdoutSerializer.new
end

Instance Attribute Details

#objectsObject (readonly)

The set of objects to include in the graph.

Since:

  • 0.6.0



31
32
33
# File 'lib/yard/cli/graph.rb', line 31

def objects
  @objects
end

#optionsObject (readonly)

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

:format => :dot

Since:

  • 0.6.0



28
29
30
# File 'lib/yard/cli/graph.rb', line 28

def options
  @options
end

Instance Method Details

#descriptionObject

Since:

  • 0.6.0



42
43
44
# File 'lib/yard/cli/graph.rb', line 42

def description
  "Graphs class diagram using Graphviz"
end

#run(*args) ⇒ Object

Runs the command-line utility.

Examples:

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

Parameters:

Since:

  • 0.6.0



52
53
54
55
56
57
58
59
60
61
# File 'lib/yard/cli/graph.rb', line 52

def run(*args)
  parse_arguments(*args)

  contents = objects.map do |o|
    o.format(options.merge(:serialize => false))
  end.join("\n")
  opts = {:type => :layout, :contents => contents}
  options.update(opts)
  Templates::Engine.render(options)
end