GithubHelp home page GithubHelp logo

vesan / aasm_statecharts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from workflowsonrails/aasm_statecharts

0.0 0.0 0.0 216 KB

Render AASM state machines to UML statecharts.

License: MIT License

Ruby 100.00%

aasm_statecharts's Introduction

aasm_statecharts

aasm_statecharts is a utility for generating UML statechart diagrams from state machines defined using AASM. Unlike other state diagram generators, it can express extended finite state machine concepts such as guards and entry actions.

Installation and Invokation

You can install aasm_statecharts from RubyGems using gem install aasm_statecharts, or add the aasm_statecharts gem to your Gemfile and run Bundler to install it.

If you have installed aasm_statecharts via gem, you can invoke it using the command aasm_statecharts; otherwise, if you have used Bundler without generating binstubs, you can invoke it with the command bundle exec aasm_statecharts. The following assumes that it has been installed via gem for simplicity.

Example

Considuer following model, which is assumed to be stored in app/models/claim.rb:

class Claim < ActiveRecord::Base
  belongs_to :user
  validates :title, presence: true
  validates :description, presence: true

  include AASM

  aasm do
    state :unsubmitted, initial: true
    state :submitted, exit: [:cancel_deadline, :close_ticket]
    state :resolved, final: true

    event :submit do
      transitions from: :unsubmitted, to: :submitted,
                  guard: :accepting_claims?,
                  on_transition: :notify_submitted
    end
    event :return do
      transitions from: :submitted, to: :unsubmitted
    end
    event :accept do
      transitions from: :submitted, to: :resolved
    end
  end
  
  def accepting_claims?
  end
  
  def cancel_deadline
  end

  def close_ticket
  end
  
  def notify_submitted
  end
end

If we invoke aasm_statecharts claim, then the following diagram will be written to ./doc/claim.png:

Claim Statechart

Usage

For more advanced usage information, see aasm_statecharts --help:

Usage: aasm_statecharts [options] <model> [models ...]
    -a, --all                        Render all models using AASM
    -d, --directory directory        Output to a specific directory (default: ./doc)
    -t, --file-type type             Output in the specified format (default: png),
which must be one of the following: bmp, canon, dot, xdot, cmap, dia, eps, fig, gd,
gd2, gif, gtk, hpgl, ico, imap, cmapx, imap_np, cmapx_np, ismap, jpeg, jpg, jpe, mif,
mp, pcl, pdf, pic, plain, plain-ext, png, ps, ps2, svg, svgz, tga, tiff, tif, vml,
vmlz, vrml, vtx, wbmp, xlib, none.

aasm_statecharts's People

Contributors

bremac avatar argonanth avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.