### Home Classes Methods

### In Files

- lib/state_machine/graph.rb

### Parent

GraphViz

### Methods

- ::new
- #add_edges
- #add_nodes
- #output

### Included Modules

- StateMachine::Assertions

### Files

- LICENSE

### Class/Module Index

Quicksearch

- StateMachine
- StateMachine::AllMatcher
- StateMachine::Assertions
- StateMachine::AttributeTransitionCollection
- StateMachine::BlacklistMatcher
- StateMachine::Branch
- StateMachine::Callback
- StateMachine::ClassMethods
- StateMachine::Error
- StateMachine::EvalHelpers
- StateMachine::Event
- StateMachine::EventCollection
- StateMachine::Graph
- StateMachine::InstanceMethods
- StateMachine::IntegrationNotFound
- StateMachine::Integrations
- StateMachine::Integrations::ActiveModel
- StateMachine::Integrations::ActiveModel::Observer
- StateMachine::Integrations::ActiveModel::ObserverUpdate
- StateMachine::Integrations::ActiveRecord
- StateMachine::Integrations::Base
- StateMachine::Integrations::Base::ClassMethods
- StateMachine::Integrations::DataMapper
- StateMachine::Integrations::DataMapper::Observer
- StateMachine::Integrations::MongoMapper
- StateMachine::Integrations::Mongoid
- StateMachine::Integrations::Sequel
- StateMachine::InvalidEvent
- StateMachine::InvalidParallelTransition
- StateMachine::InvalidTransition
- StateMachine::LoopbackMatcher
- StateMachine::Machine
- StateMachine::MachineCollection
- StateMachine::MacroMethods
- StateMachine::Matcher
- StateMachine::MatcherHelpers
- StateMachine::NodeCollection
- StateMachine::Path
- StateMachine::PathCollection
- StateMachine::RailsEngine
- StateMachine::State
- StateMachine::StateCollection
- StateMachine::StateContext
- StateMachine::Transition
- StateMachine::TransitionCollection
- StateMachine::WhitelistMatcher
- StateMachine::YARD
- StateMachine::YARD::Handlers
- StateMachine::YARD::Handlers::Base
- StateMachine::YARD::Handlers::Event
- StateMachine::YARD::Handlers::Machine
- StateMachine::YARD::Handlers::State
- StateMachine::YARD::Handlers::Transition
- Object

No matching classes.

# StateMachine::Graph

Provides a set of higher-order features on top of the raw GraphViz graphs

### Attributes

file_format[R]

The image format to generate the graph in

file_path[R]

The graph's full filename

font[R]

The name of the font to draw state names in

### Public Class Methods

new(name, options = {}) click to toggle source

Creates a new graph with the given name.

Configuration options:

- `:path` - The path to write the graph file to. Default is the current directory (".").

- `:format` - The image format to generate the graph in. Default is "png'.

- `:font` - The name of the font to draw state names in. Default is "Arial".

- `:orientation` - The direction of the graph ("portrait" or "landscape"). Default is "portrait".

    # File lib/state_machine/graph.rb, line 37
    def initialize(name, options = {})
      options = {:path => '.', :format => 'png', :font => 'Arial', :orientation => 'portrait'}.merge(options)
      assert_valid_keys(options, :path, :format, :font, :orientation)

      @font = options[:font]
      @file_path = File.join(options[:path], "#{name}.#{options[:format]}")
      @file_format = options[:format]

      super('G', :rankdir => options[:orientation] == 'landscape' ? 'LR' : 'TB')
    end

### Public Instance Methods

add_edges(*args) click to toggle source

Adds a new edge to the graph. The font for the edge will be automatically set based on the graph configuration. The generated edge will be returned.

For example,

    graph = StateMachine::Graph.new('test')
    graph.add_edges('parked', 'idling', :label => 'ignite')

    # File lib/state_machine/graph.rb, line 75
    def add_edges(*args)
      edge = v0_api? ? add_edge(*args) : super
      edge.fontname = @font
      edge
    end

add_nodes(*args) click to toggle source

Adds a new node to the graph. The font for the node will be automatically set based on the graph configuration. The generated node will be returned.

For example,

    graph = StateMachine::Graph.new('test')
    graph.add_nodes('parked', :label => 'Parked', :width => '1', :height => '1', :shape => 'ellipse')

    # File lib/state_machine/graph.rb, line 62
    def add_nodes(*args)
      node = v0_api? ? add_node(*args) : super
      node.fontname = @font
      node
    end

output() click to toggle source

Generates the actual image file based on the nodes / edges added to the graph. The path to the file is based on the configuration options for this graph.

    # File lib/state_machine/graph.rb, line 51
    def output
      super(@file_format => @file_path)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.