{"id":18103130,"url":"https://github.com/katee/aasm-diagram","last_synced_at":"2025-04-06T10:14:32.350Z","repository":{"id":25120520,"uuid":"103193315","full_name":"Katee/aasm-diagram","owner":"Katee","description":"Generate diagrams of AASM state machines.","archived":false,"fork":false,"pushed_at":"2023-06-29T20:17:18.000Z","size":83,"stargazers_count":72,"open_issues_count":6,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T09:08:44.036Z","etag":null,"topics":["aasm","graphviz","ruby","state-machine"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Katee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-11T22:10:36.000Z","updated_at":"2025-03-06T15:48:25.000Z","dependencies_parsed_at":"2024-06-18T23:08:00.240Z","dependency_job_id":null,"html_url":"https://github.com/Katee/aasm-diagram","commit_stats":{"total_commits":21,"total_committers":7,"mean_commits":3.0,"dds":0.2857142857142857,"last_synced_commit":"e52b3ed08cb79f99c11a719bd5bc667d14f7e96b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katee%2Faasm-diagram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katee%2Faasm-diagram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katee%2Faasm-diagram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Katee%2Faasm-diagram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Katee","download_url":"https://codeload.github.com/Katee/aasm-diagram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247464226,"owners_count":20942970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aasm","graphviz","ruby","state-machine"],"created_at":"2024-10-31T22:10:25.203Z","updated_at":"2025-04-06T10:14:32.316Z","avatar_url":"https://github.com/Katee.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AASM Diagram\n\n[AASM Diagram](https://github.com/katee/aasm-diagram) creates diagrams for [AASM](https://github.com/aasm/aasm) state machines. To take an example from the AASM Readme:\n\n```ruby\nrequire 'aasm-diagram'\n\nclass Job\n  include AASM\n\n  aasm do\n    state :sleeping, :initial =\u003e true\n    state :running, :cleaning\n\n    event :run do\n      transitions :from =\u003e :sleeping, :to =\u003e :running\n    end\n\n    event :clean do\n      transitions :from =\u003e :running, :to =\u003e :cleaning\n    end\n\n    event :sleep do\n      transitions :from =\u003e [:running, :cleaning], :to =\u003e :sleeping\n    end\n  end\nend\n\njob = Job.new\n\nAASMDiagram::Diagram.new(job.aasm, 'docs/job.png')\n```\n\nGenerates the following diagram:\n\n![Diagram of Job state machine](docs/job.png)\n\n## Installation\n\n- Install Graphviz ([see the rails-erd guide for more details](https://voormedia.github.io/rails-erd/install.html)). If you use Homebrew try `brew install graphviz`.\n- Add `gem 'aasm-diagram', require: false, group: :development` to your `Gemfile` and run `bundle`.\n\n## Integration\n\nThe gem exposes the `generate` Rake task, that can be used to generate the diagrams of state machines into\nPNG images. The `generate` task accepts two parameters:\n\n- the name of the model, in underscored format, will be CamelCased by the task\n- the name of the state machine, for models with multiple AASMs; this argument is optional\n\nThe task will output the PNG image by default to the `/tmp` folder; but can be configured via the\n`AASM_DIAGRAM_OUTPUT_DIR` environment variable to write the files to another folder.\n\nThe filenames are generated based on the parameters as follows `model_name-state_machine_name.png`.\nIf no state machine name is provided, the task will use `default` for the file name.\n\n```sh\n# for the Order model and the :dropoff state machine\nrake aasm-diagram:generate[order,dropoff] # -\u003e tmp/order-dropoff.png\n\n# for the Invoice model and the \"default\" state machine\nrake aasm-diagram:generate[invoice] # -\u003e tmp/invoice-default.png\n\n# with custom output directory\nAASM_DIAGRAM_OUTPUT_DIR=docs rake aasm-diagram:generate[invoice] # -\u003e docs/invoice-default.png\n```\n\n### Rails\n\nOnce installed, the gem automatically integrates with Rails via Railties and exposes the task automatically.\n\n`rails aasm-diagram:generate[my_model,my_state_machine]`\n\nIf the model contains only one state machine, or you just want to generate for the \"default\" one\nyou can skip the state machine name parameter.\n\n`rails aasm-diagram:generate[my_model]`\n\n### Plain Ruby\n\nFor plain Ruby projects the gem includes a Rakefile that can be loaded in your project's Rakefile,\nusing source code along the lines of:\n\n```ruby\n# in Rakefile\n\nrequire 'aasm-diagram'\n\nspec = Gem::Specification.find_by_name 'aasm-diagram'\nrakefile = \"#{spec.gem_dir}/lib/aasm_diagram/Rakefile\"\nload rakefile\n```\n\n## More Examples\n\n### Guards\n\n```ruby\nclass Cleaner\n  include AASM\n\n  aasm do\n    state :idle, :initial =\u003e true\n    state :cleaning\n\n    event :clean do\n      transitions :from =\u003e :idle, :to =\u003e :cleaning, :guard =\u003e :cleaning_needed?\n    end\n\n    event :clean_if_needed do\n      transitions :from =\u003e :idle, :to =\u003e :cleaning do\n        guard do\n          cleaning_needed?\n        end\n      end\n      transitions :from =\u003e :idle, :to =\u003e :idle\n    end\n\n    event :clean_if_dirty do\n      transitions :from =\u003e :idle, :to =\u003e :cleaning, :guard =\u003e :if_dirty?\n    end\n  end\n\n  def cleaning_needed?\n    false\n  end\n\n  def if_dirty?(status)\n    status == :dirty\n  end\nend\n\ncleaner = Cleaner.new\nAASMDiagram::Diagram.new(job.aasm, '../docs/guard-cleaner.png')\n```\n\n![Diagram of Cleaner state machine](docs/guard-cleaner.png)\n\n### Multiple state machines per class\n\n```ruby\nclass SimpleMultipleExample\n  include AASM\n  aasm(:move) do\n    state :standing, :initial =\u003e true\n    state :walking\n    state :running\n\n    event :walk do\n      transitions :from =\u003e :standing, :to =\u003e :walking\n    end\n    event :run do\n      transitions :from =\u003e [:standing, :walking], :to =\u003e :running\n    end\n    event :hold do\n      transitions :from =\u003e [:walking, :running], :to =\u003e :standing\n    end\n  end\n\n  aasm(:work) do\n    state :sleeping, :initial =\u003e true\n    state :processing\n\n    event :start do\n      transitions :from =\u003e :sleeping, :to =\u003e :processing\n    end\n    event :stop do\n      transitions :from =\u003e :processing, :to =\u003e :sleeping\n    end\n  end\nend\n\nsimple = SimpleMultipleExample.new\nAASMDiagram::Diagram.new(simple.aasm(:move), 'docs/multiple-state-machines-1.png')\nAASMDiagram::Diagram.new(simple.aasm(:work), 'docs/multiple-state-machines-2.png')\n```\n\nGenerates two images:\n\n![Diagram of state machine 1](docs/multiple-state-machines-1.png)\n![Diagram of state machine 2](docs/multiple-state-machines-2.png)\n\n## Notes\n\nAASM Diagram is heavily inspired by [rails-erd](https://github.com/voormedia/rails-erd).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatee%2Faasm-diagram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatee%2Faasm-diagram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatee%2Faasm-diagram/lists"}