Sha256: 3645349074fff4a7df8b1ab7029ed3b15dc72314f12438d3c91e0b21ab9e0558

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

namespace :state_machine do
  desc 'Draws state machines using GraphViz (options: CLASS=User,Vehicle; FILE=user.rb,vehicle.rb [not required in Rails / Merb]; FONT=Arial; FORMAT=png; ORIENTATION=portrait'
  task :draw do
    # Build drawing options
    options = {}
    options[:file] = ENV['FILE'] if ENV['FILE']
    options[:path] = ENV['TARGET'] if ENV['TARGET']
    options[:format] = ENV['FORMAT'] if ENV['FORMAT']
    options[:font] = ENV['FONT'] if ENV['FONT']
    options[:orientation] = ENV['ORIENTATION'] if ENV['ORIENTATION']
    
    if defined?(Rails)
      puts "Files are automatically loaded in Rails; ignoring FILE option" if options.delete(:file)
      Rake::Task['environment'].invoke
    elsif defined?(Merb)
      puts "Files are automatically loaded in Merb; ignoring FILE option" if options.delete(:file)
      Rake::Task['merb_env'].invoke
      
      # Fix ruby-graphviz being incompatible with Merb's process title
      $0 = 'rake'
    else
      # Load the library
      $:.unshift(File.dirname(__FILE__) + '/..')
      require 'state_machine'
    end
    
    StateMachine::Machine.draw(ENV['CLASS'], options)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
state_machine-1.1.2 lib/tasks/state_machine.rb
state_machine-1.1.1 lib/tasks/state_machine.rb
state_machine-1.1.0 lib/tasks/state_machine.rb
state_machine-1.0.3 lib/tasks/state_machine.rb