123456789_123456789_123456789_123456789_123456789_

Class: YARD::CLI::Graph

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: YARD::CLI::YardoptsCommand
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

YardoptsCommand - Inherited

DEFAULT_YARDOPTS_FILE

Class Method Summary

  • .new ⇒ Graph constructor

    Creates a new instance of the command-line utility.

YardoptsCommand - Inherited

.new

Creates a new command that reads .yardopts.

Command - Inherited

.run

Helper method to run the utility on an instance.

Instance Attribute Summary

  • #objects readonly

    The set of objects to include in the graph.

  • #options readonly

    The options parsed out of the commandline.

YardoptsCommand - Inherited

#options_file

The options file name (defaults to DEFAULT_YARDOPTS_FILE).

#use_document_file, #use_yardopts_file

Instance Method Summary

YardoptsCommand - Inherited

#parse_arguments

Parses commandline arguments.

#parse_rdoc_document_file, #parse_yardopts,
#parse_yardopts_options

Parses out the yardopts/document options.

#support_rdoc_document_file!

Reads a .document file in the directory to get source file globs.

#yardopts

Parses the .yardopts file for default yard options.

Command - Inherited

Constructor Details

.newGraph

Creates a new instance of the command-line utility

Since:

  • 0.6.0

[ GitHub ]

  
# 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 (readonly)

The set of objects to include in the graph.

Since:

  • 0.6.0

[ GitHub ]

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

attr_reader :objects

#options (readonly)

The options parsed out of the commandline. Default options are: :format => :dot

Since:

  • 0.6.0

[ GitHub ]

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

attr_reader :options

Instance Method Details

#description

Since:

  • 0.6.0

[ GitHub ]

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

def description
  "Graphs class diagram using Graphviz"
end

#optparse(*args) (private)

Parses commandline options.

Parameters:

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/graph.rb', line 69

def optparse(*args)
  visibilities = [:public]
  opts = OptionParser.new

  opts.separator ""
  opts.separator "General Options:"

  opts.on('-b', '--db FILE', 'Use a specified .yardoc db to load from or save to. (defaults to .yardoc)') do |yfile|
    YARD::Registry.yardoc_file = yfile
  end

  opts.on('--full', 'Full class diagrams (show methods and attributes).') do
    options[:full] = true
  end

  opts.on('-d', '--dependencies', 'Show mixins in dependency graph.') do
    options[:dependencies] = true
  end

  opts.on('--no-public', "Don't show public methods. (default shows public)") do
    visibilities.delete(:public)
  end

  opts.on('--protected', "Show or don't show protected methods. (default hides protected)") do
    visibilities.push(:protected)
  end

  opts.on('--private', "Show or don't show private methods. (default hides private)") do
    visibilities.push(:private)
  end

  opts.separator ""
  opts.separator "Output options:"

  opts.on('--dot [OPTIONS]', 'Send the results directly to `dot` with optional arguments.') do |dotopts|
    options.serializer = Serializers::ProcessSerializer.new('dot ' + dotopts.to_s)
  end

  opts.on('-f', '--file [FILE]', 'Writes output to a file instead of stdout.') do |file|
    options.serializer = Serializers::FileSystemSerializer.new(:basepath => '.', :extension => nil)
    options.serializer.instance_eval "def serialized_path(object) #{file.inspect} end"
  end

  common_options(opts)
  parse_options(opts, args)

  Registry.load

  expression = "#{visibilities.uniq.inspect}.include?(object.visibility)"
  options.verifier = Verifier.new(expression)
  @objects = args.first ?
    args.map {|o| Registry.at(o) }.compact :
    [Registry.root]
end

#run(*args)

Runs the command-line utility.

Examples:

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

Parameters:

Since:

  • 0.6.0

[ GitHub ]

  
# 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

#unrecognized_option(err) (private)

Since:

  • 0.6.0

[ GitHub ]

  
# File 'lib/yard/cli/graph.rb', line 65

def unrecognized_option(err) end