Class: DataMapper::Visualizer::Rake::GraphVizTask

Inherits:
Task
  • Object
show all
Defined in:
lib/dm-visualizer/rake/graphviz_task.rb

Direct Known Subclasses

Rails::GraphVizTask

Constant Summary collapse

DIAGRAMS =

The types of GraphViz diagrams.

Set[:relational, :schema]
FORMATS =

The image formats for GraphViz diagrams.

Set[:png, :svg]

Instance Attribute Summary collapse

Attributes inherited from Task

#options

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|task| ... } ⇒ GraphVizTask

Creates a new dm:doc:graphviz task.

Parameters:

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

    Additional options.

Options Hash (options):

  • :relational (Boolean)

    Specifies whether to generate a relational diagram.

  • :schema (Boolean)

    Specifies whether to generate a schema diagram.

  • :png (Boolean)

    Specifies whether to generate a PNG image.

  • :svg (Boolean)

    Specifies whether to generate a SVG image.

Yields:

  • (task)

    The given block will be passed the newly created task.

Yield Parameters:

See Also:

  • GraphViz.new


49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dm-visualizer/rake/graphviz_task.rb', line 49

def initialize(options={},&block)
  extract_options = lambda { |keys|
    if keys.any? { |key| options[key] }
      keys.select { |key| options.delete(key) }
    else
      keys
    end
  }

  @diagrams = extract_options[DIAGRAMS]
  @formats  = extract_options[FORMATS]

  super(options,&block)
end

Instance Attribute Details

#diagramsObject (readonly)

The types of diagrams to generate.



18
19
20
# File 'lib/dm-visualizer/rake/graphviz_task.rb', line 18

def diagrams
  @diagrams
end

#formatsObject (readonly)

The formats of the diagrams to generate.



21
22
23
# File 'lib/dm-visualizer/rake/graphviz_task.rb', line 21

def formats
  @formats
end

Instance Method Details

#defineObject

Defines the dm:doc:graphviz namespace.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dm-visualizer/rake/graphviz_task.rb', line 67

def define
  super do
    namespace(:graphviz) do
      @diagrams.each do |type|
        namespace(type) do
          @formats.each do |format|
            desc "Generates a #{format.to_s.upcase} GraphViz #{type} diagram of the DataMapper Models"
            task(format) do
              GraphViz.new(@options.merge(
                :naming => type,
                :file   => "doc/#{type}_diagram",
                :format => format
              )).visualize!
            end
          end
        end

        task(type => @formats.map { |format| "#{type}:#{format}" })
      end
    end

    task(:graphviz => @diagrams.map { |type| "graphviz:#{type}" })
  end
end