Class: AppDiagram

Inherits:
Object
  • Object
show all
Defined in:
lib/railroad/app_diagram.rb

Overview

Root class for RailRoad diagrams

Direct Known Subclasses

AasmDiagram, ControllersDiagram, ModelsDiagram

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AppDiagram

Returns a new instance of AppDiagram.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/railroad/app_diagram.rb', line 10

def initialize(options)
  @options = options
  @graph = DiagramGraph.new
  @graph.show_label = @options.label

  STDERR.print "Loading application environment\n" if @options.verbose
  load_environment

  STDERR.print "Loading application classes\n" if @options.verbose
  load_classes
end

Instance Method Details

Print diagram



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/railroad/app_diagram.rb', line 23

def print
  if @options.output
    old_stdout = STDOUT.dup
    begin
      STDOUT.reopen(@options.output)
    rescue
      STDERR.print "Error: Cannot write diagram to #{@options.output}\n\n"
      exit 2
    end
  end

  STDOUT.print to_s
  
  if @options.output
    STDOUT.reopen(old_stdout)
  end
end

#to_sObject

print



41
42
43
44
45
46
47
48
49
# File 'lib/railroad/app_diagram.rb', line 41

def to_s
  if @options.xmi 
      STDERR.print "Generating XMI diagram\n" if @options.verbose
  	@graph.to_xmi
  else
      STDERR.print "Generating DOT graph\n" if @options.verbose
      @graph.to_dot 
  end
end