{"id":18978024,"url":"https://github.com/simplificator/fsm","last_synced_at":"2026-03-09T08:02:01.488Z","repository":{"id":569197,"uuid":"200649","full_name":"simplificator/fsm","owner":"simplificator","description":"a simple finite state machine gem","archived":false,"fork":false,"pushed_at":"2011-10-24T10:42:32.000Z","size":195,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-02-19T03:57:23.242Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplificator.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-05-14T07:36:04.000Z","updated_at":"2014-07-29T06:36:25.000Z","dependencies_parsed_at":"2022-07-05T00:30:25.446Z","dependency_job_id":null,"html_url":"https://github.com/simplificator/fsm","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/simplificator/fsm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplificator%2Ffsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplificator%2Ffsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplificator%2Ffsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplificator%2Ffsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplificator","download_url":"https://codeload.github.com/simplificator/fsm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplificator%2Ffsm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30287446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T02:57:19.223Z","status":"ssl_error","status_checked_at":"2026-03-09T02:56:26.373Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-08T15:31:52.922Z","updated_at":"2026-03-09T08:02:01.465Z","avatar_url":"https://github.com/simplificator.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fsm\n\nFSM is a simple finite state machine gem. You can define your State Machine with a \"DSL\".\n\n## Status\nFSM is still under development so the interface can/might/will change, features will be added (and perhaps removed again)\nBut if you are interested in this project, then use it and tell us what you think/need/want/like/don't like. We are open\nfor suggestions!\n\n## Usage\n    class Water\n      include FSM\n      # The state machine is specified as a block in define_fsm.\n      define_fsm do\n        # now define all the states\n        # you can add :enter / :exit callbacks (callback can be a String, Symbol or Proc)\n        # these callbacks are triggered on any transition from/to this state.\n        \n        states(:gas, :liquid) # shortcut to define several states but you can not specify callbacks\n        state(:solid, :enter =\u003e :on_enter_solid, :exit =\u003e :on_exit_solid)\n        \n        # define all valid transitions (arguments are name of transition, from state name, to state name)\n        # you can define callbacks which are called only on this transition as well as guards \n        # guards prevent transition when they return nil/false\n        transition(:heat_up, :solid, :liquid, :event =\u003e :on_heat, :guard =\u003e :guard_something)\n        transition(:heat_up, :liquid, :gas, :event =\u003e :on_heat)     # look mam.... two transitions with same name\n        transition(:cool_down, [:gas, :liquid], :liquid, :event =\u003e :on_cool)\n        \n        # define the attribute which is used to store the state (defaults to :state)\n        state_attribute(:state_of_material)\n        \n        # define the initial state (defaults to the first state defined - :gas in this sample)\n        initial(:liquid)\n      end\n      \n      private\n      # callbacks here...\n      def ...\n      \n      # \n      def guard_something()\n        \n      end\n    end\n    \n    # then you can call these methods\n    w = Water.new\n    w.heat_up  # the name of the transition is the name of the method\n    w.reachable_state_names\n    w.available_transition_names\n    w.cool_down # again... it's the name of the transition\n    w.state_of_material\n    w.state_liquid?\n    w.state_solid?\n    \n    \n## Guards\nGuards are methods or Procs which can prevent a transition. To do so they just need to return false/nil. If no guard is specified\nthen the transition is always executed.\n\n## Callbacks and arguments\nIf the :enter/:exit callbacks are methods, then they are not passed any arguments, if it's a Proc, \nthen a single argument (the caller) is passed.\nShort: :enter/:exit methods must take 0 arguments, :enter/:exit Procs must take one argument.\n\nIf :event and :guard callbacks are methods then they are passed all the arguments that were passed to the transition method.\nWith Procs for :event and :guard the caller as well as all the arguments passed to the transition methods are passed.\n\n   \n## Order of callbacks/guards calls\nThe callbacks/guards are called in following order if the guard returns __true__:\n  * :exit (state)\n  * :guard (transition)\n  * :event (transition)\n  * :enter (state) \n  \nThe callbacks/guards are called in following order if the guard returns __false__:\n  * :exit (state)\n  * :guard (transition)\n\n\n## Graphviz / Dot format\nFSM supports the dot format of graphviz (http://www.graphviz.org/).\nIf you have the graphviz tools installed (the dot executable must be on the path) then\nyou can export a graph to png like this\n    # Export to water.png in the current dir\n    Water.draw_graph    \n    # Export in another format. (see graphviz documentation for supported file formats)\n    Water.draw_graph(:format =\u003e :foo)\n    # Change the extension (defaults to the format)\n    Water.draw_graph(:format =\u003e :jpg, :extension =\u003e :jpeg)\n    # Specify a custom file\n    Water.draw_graph(:outfile =\u003e '/afile.png')\n  \n    \n## Copyright\nCopyright (c) 2009 simplificator GmbH. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplificator%2Ffsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplificator%2Ffsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplificator%2Ffsm/lists"}