Module: RDot

Defined in:
lib/rdot.rb,
lib/rdot-common.rb

Constant Summary

VERSION =
'1.1.1'

Class Method Summary collapse

Class Method Details

.defaultsHash

Default values for dot options.

Returns:

  • (Hash)

    see source for details or dot for description.



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/rdot.rb', line 386

def defaults
  {
    :graph_fontname                 => 'sans-serif',
    :graph_fontsize                 => 24,
    :graph_label                    => 'RDot Graph',
    :node_fontname                  => 'monospace',
    :node_fontsize                  => 9,
    :color_class                    => '#77FF77',
    :color_class_preloaded          => '#AAFFAA',
    :color_class_core               => '#DDFFDD',
    :color_exception                => '#FF7777',
    :color_exception_preloaded      => '#FFAAAA',
    :color_exception_core           => '#FFDDDD',
    :color_module                   => '#9999FF',
    :color_module_preloaded         => '#BBBBFF',
    :color_module_core              => '#DDDDFF',
#         :color_class                    => '#BBFFBB',
#         :color_class_preloaded          => '#CCEECC',
#         :color_class_core               => '#DDFF99',
#         :color_exception                => '#FFBBBB',
#         :color_exception_preloaded      => '#EECCCC',
#         :color_exception_core           => '#FFDD99',
#         :color_module                   => '#BBBBFF',
#         :color_module_preloaded         => '#CCCCEE',
#         :color_module_core              => '#99DDFF',
    :color_protected                => '#EEEEEE',
    :color_private                  => '#DDDDDD',
    :color_inherited                => '#0000FF',
    :color_included                 => '#00AAFF',
    :color_extended                 => '#AA00FF',
    :color_nested                   => '#EEEEEE',
    :graph_splines                  => 'spline'
  }
end

.diff(base, other, opts = {}) ⇒ Hash

Make diff between two objectspaces.

Parameters:

  • base (Hash)

    'New' objectspace.

  • other (Hash)

    'Old' objectspace

  • opts (Hash) (defaults to: {})

    Options (see also snapshot & dot).

Options Hash (opts):

  • :show_preloaded (Boolean)

    if true old classes/modules will not deleted from difference.

Returns:

  • (Hash)

    Difference objectspace.



359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/rdot.rb', line 359

def diff base, other, opts = {}
  opts = defaults.merge opts
  if other == nil
    return base
  end
  result = {}
  base.each do |n, m|
    d = diff_module m, other[n], opts
    result[n] = d if d
  end
  result
end

.dot(space, opts = {}) ⇒ String

Make .dot text from snapshot or difference.

Parameters:

  • space (Hash)

    Snapshot or difference objectspace.

  • opts (Hash) (defaults to: {})

    Options (see also snapshot & diff). This Hash will be merged over default values (see defaults).

Options Hash (opts):

  • :color_class (String)

    class node title background color;

  • :color_class_core (String)

    core class node title background color;

  • :color_class_preloaded (String)

    preloaded class node title background color;

  • :color_exception (String)

    exception node title background color;

  • :color_exception_core (String)

    core exception node title background color;

  • :color_exception_preloaded (String)

    preloaded exception node title background color;

  • :color_extended (String)

    color of 'extended' edges;

  • :color_included (String)

    color of 'included' edges;

  • :color_inherited (String)

    color of 'inherited' edges;

  • :color_module (String)

    module node title background color;

  • :color_module_core (String)

    core module node title background color;

  • :color_module_preloaded (String)

    preloaded module title background color;

  • :color_nested (String)

    color of 'nested' edges;

  • :color_private (String)

    background color for private methods;

  • :color_protected (String)

    background color for protected methods;

  • :graph_fontname (String)

    font name of graph title;

  • :graph_fontsize (Numeric)

    font size of graph title;

  • :graph_label (String)

    graph title;

  • :hide_extended (Boolean)

    if true hide 'extended' edges;

  • :hide_included (Boolean)

    if true hide 'included' edges;

  • :hide_nested (Boolean)

    if true hide 'nested' edges;

  • :node_fontname (String)

    font name of class/module nodes;

  • :node_fontsize (Numeric)

    font size of class/module nodes.

Returns:

  • (String)

    Text of .dot-file.



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
# File 'lib/rdot.rb', line 692

def dot space, opts = {}
  opts = defaults.merge opts
  result = []
  result << 'digraph graph_RDot{'
  result << '  graph['
  result << '    rankdir=RL,'
  result << '    splines=' + opts[:graph_splines] + ','
  result << '    labelloc=t,searchsize=1000,'
  result << '    fontname="' + opts[:graph_fontname] + '",'
  result << '    fontsize=' + opts[:graph_fontsize].to_s + ','
  result << '    label="' + opts[:graph_label] + '"'
  result << '  ];'
  result << '  node['
  result << '    shape=plaintext,'
  result << '    fontname="' + opts[:node_fontname] + '",'
  result << '    fontsize=' + opts[:node_fontsize].to_s + ''
  result << '  ];'
  result << '  edge['
#      result << '    dir=back,'
#      result << '    arrowhead=vee,'
  result << '    penwidth=0.5, arrowsize=0.5'
  result << '  ];'
  result << '  nullnode[label=""];'
#      result << '  nullnode -> ' + node_name('Kernel') + '[color=yellow,weight=0,minlen=0];'
  @processed = []
  @nested = []
  @extended = []
  @included = []
  @inherited = []
  space.each do |n, m|
    mm = dot_module space, n, m, opts
    result << '  ' + mm if mm
  end
  result << '  subgraph subNested{'
  result << '    edge['
  result << '      color="' + opts[:color_nested] + '",'
  result << '      weight=1,'
  result << '      minlen=0'
  result << '    ];'
  result << '    ' + @nested.join("\n    ")
  result << '  }'
  result << '  subgraph subExtended{'
  result << '    edge['
  result << '      color="' + opts[:color_extended] + '",'
  result << '      weight=1,'
  result << '      minlen=0'
  result << '    ];'
  result << '    ' + @extended.join("\n    ")
  result << '  }'
  result << '  subgraph subIncluded{'
  result << '    edge['
  result << '      color="' + opts[:color_included] + '",'
  result << '      weight=2,'
  result << '      minlen=1'
  result << '    ];'
  result << '    ' + @included.join("\n    ")
  result << '  }'
  result << '  subgraph subInherited{'
  result << '    edge['
  result << '      color="' + opts[:color_inherited] + '",'
  result << '      weight=4,'
  result << '      minlen=1'
  result << '    ];'
  result << '    ' + @inherited.join("\n    ")
  result << '  }'
  result << '}'
  result.join "\n"
end

.get_file(file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rdot-common.rb', line 9

def get_file file
  src = File.expand_path file
  $:.each do |dir|
    dir = File.expand_path dir
    len = dir.length
    if src[0...len] == dir
      src = src[len..-1]
      if src[0] == '/'
        src = src[1..-1]
      end
      return src
    end
  end
  return file
end

.snapshot(opts = {}) ⇒ Hash

Make hash with data of objectspace.

Parameters:

  • opts (Hash) (defaults to: {})

    Options (see also dot & diff).

Options Hash (opts):

  • :exclude_classes (Array<Class>)

    don't add classes listed and their descendants;

  • :exclude_files (Array<String>)

    don't add methods defined in files listed;

  • :exclude_namespaces (Array<Module>)

    don't add classes/modules listed and their inners;

  • :filter_classes (Array<Class>)

    add only classes listed and their descendants;

  • :filter_files (Array<String>)

    add only methods defined in files listed;

  • :filter_global (Boolean)

    add only classes/modules in global namespace;

  • :filter_namespaces (Array<Module>)

    add only classes/modules listed and their inners;

  • :hide_arguments (Boolean)

    don't add arguments info to methods' names;

  • :hide_constants (Boolean)

    don't add constants' data;

  • :hide_methods (Boolean)

    don't add methods' data;

  • :select_attributes (Boolean)

    make attributes data instead getter and setter methods;

  • :show_private (Boolean)

    add data of private methods;

  • :show_protected (Boolean)

    add data of protected methods.

Returns:

  • (Hash)

    Objectspace.



289
290
291
292
293
294
# File 'lib/rdot.rb', line 289

def snapshot opts = {}
  opts = defaults.merge opts
  result = {}
  ObjectSpace.each_object(Module) { |m| add_module result, m, opts }
  result
end