{"id":13463327,"url":"https://github.com/svenfuchs/simple_states","last_synced_at":"2025-04-07T10:22:15.286Z","repository":{"id":56895849,"uuid":"2133652","full_name":"svenfuchs/simple_states","owner":"svenfuchs","description":"A super-slim statemachine-like support library","archived":false,"fork":false,"pushed_at":"2017-07-25T12:09:49.000Z","size":103,"stargazers_count":96,"open_issues_count":4,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T08:09:07.486Z","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/svenfuchs.png","metadata":{"files":{"readme":"README.md","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":"2011-07-31T20:17:20.000Z","updated_at":"2024-11-07T09:21:23.000Z","dependencies_parsed_at":"2022-08-21T01:20:59.343Z","dependency_job_id":null,"html_url":"https://github.com/svenfuchs/simple_states","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fsimple_states","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fsimple_states/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fsimple_states/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svenfuchs%2Fsimple_states/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svenfuchs","download_url":"https://codeload.github.com/svenfuchs/simple_states/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247631861,"owners_count":20970070,"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":[],"created_at":"2024-07-31T13:00:51.042Z","updated_at":"2025-04-07T10:22:15.256Z","avatar_url":"https://github.com/svenfuchs.png","language":"Ruby","funding_links":[],"categories":["Rails Plugins","Ruby","State Machines"],"sub_categories":["State Machines"],"readme":"# simple\\_states [![Build Status](https://secure.travis-ci.org/svenfuchs/simple_states.png)](http://travis-ci.org/svenfuchs/simple_states)\n\nA super-slim (~200 loc) statemachine-like support library focussed on use in\nTravis CI.\n\nNote that the current version behaves slightly differently, and comes with\nreduced features compared to the original version. If you are looking for the\noriginal version see the tag `v1.1.0.rc11`.\n\n## Usage\n\nDefine states and events like this:\n\n``` ruby\nclass Foo\n  include SimpleStates\n\n  event :start,  if: :start?\n  event :finish, to: [:passed, :failed], after: :notify, unless: :finished?\n\n  attr_accessor :state, :started_at, :finished_at\n\n  def start\n    # start foo\n  end\n\n  def start?\n    true\n  end\n\n  def notify(event)\n    # notify about event on foo\n  end\nend\n```\n\nSimpleStates expects your model to support attribute accessors for `:state`.\n\nEvent options have the following well-known meanings:\n\n``` ruby\n:to     # allowed target states to transition to, deferred from the event name if not given\n:if     # only proceed if the given method returns true\n:unless # only proceed if the given method returns false\n:before # run the given method before running `super` and setting the new state\n:after  # run the given method at the very end\n```\n\nAll of these options except can be given as a single symbol or string or as an\nArray of symbols or strings.\n\nCalling `event` will effectively add methods to a proxy module which is\nprepended to your class (included to the singleton class of your class'\ninstances on 1.9). E.g. declaring `event :start` in the example above will add\nmethods `start` and `start!` to a module included to the singleton class of\ninstances of `Foo`.\n\nThis method will\n\n1. check if `:if`/`:unless` conditions apply (if given) and just return from the method otherwise\n2. run `:before` callbacks (if given)\n3. set the object's `state` to the target state\n4. set the object's `[state]_at` attribute to `Time.now` if the object defines a writer for it\n5. call `super` if Foo defines the current method (i.e. call `start` but not `finish` in the example above)\n6. run `:after` callbacks (if given)\n\nYou can define options for all events like so:\n\n``` ruby\nevent :finish, after: :cleanup\nevent :all,    after: :notify\n```\n\nThis will call :cleanup first and then :notify on :finish.\n\nIf no target state was given for an event then SimpleStates will try to derive\nit from the event name. I.e. for an event `start` it will check the states\nlist for a state `started` and use it. If it can not find a target state this\nway then it will raise an exception.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenfuchs%2Fsimple_states","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvenfuchs%2Fsimple_states","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvenfuchs%2Fsimple_states/lists"}