# Class: YARD::CLI::Graph

Inherits:
  YardoptsCommand
  - Object
  - Command
  - YardoptsCommand
  - YARD::CLI::Graph
  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:

- #run

Since:

- 0.6.0

## Instance Attribute Summary collapse

- #objects ⇒ Object readonly

  The set of objects to include in the graph.

- #options ⇒ Object readonly

  The options parsed out of the commandline.

## Instance Method Summary collapse

- #description ⇒ Object
- #initialize ⇒ Graph constructor

  Creates a new instance of the command-line utility.

- #run(*args) ⇒ Object

  Runs the command-line utility.

## Constructor Details

### #initialize ⇒ `Graph`

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

### #objects ⇒ `Object` (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

### #options ⇒ `Object` (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

### #description ⇒ `Object`

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:

- args (`Array<String>`) —

  each tokenized argument

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