{"id":29954993,"url":"https://github.com/foca/moody","last_synced_at":"2025-08-25T00:15:22.182Z","repository":{"id":1138012,"uuid":"1016972","full_name":"foca/moody","owner":"foca","description":"Simple and straightforward implementation of the State Pattern in ruby","archived":false,"fork":false,"pushed_at":"2010-10-23T17:41:11.000Z","size":115,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-28T04:33:42.194Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foca.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}},"created_at":"2010-10-23T04:03:27.000Z","updated_at":"2016-09-22T18:47:43.000Z","dependencies_parsed_at":"2022-08-16T12:15:09.832Z","dependency_job_id":null,"html_url":"https://github.com/foca/moody","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/foca/moody","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fmoody","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fmoody/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fmoody/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fmoody/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foca","download_url":"https://codeload.github.com/foca/moody/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foca%2Fmoody/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271983712,"owners_count":24853810,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-08-03T17:08:59.915Z","updated_at":"2025-08-25T00:15:22.160Z","avatar_url":"https://github.com/foca.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Moody: An implementation of the State Pattern in ruby\n=====================================================\n\nThis is an object-oriented way to represent Finite State Machines, where an\nobject can change its behavior at runtime, depending on its internal state.\n\nIf you want more information about this pattern, read [the explanation by\nSourceMaking](http://sourcemaking.com/design_patterns/state).\n\nFor a stupid example of how you would use this, here is a traffic light:\n\n    class Stop \u003c Moody::State\n      def color\n        \"red\"\n      end\n\n      def next\n        sleep 3\n        switch_to Go\n      end\n\n      def enter\n        # turn on camera tu see who crosses on a red light\n      end\n\n      def leave\n        # turn off camera\n      end\n    end\n\n    class Go \u003c Moody::State\n      def color\n        \"green\"\n      end\n\n      def next\n        sleep 2\n        switch_to Caution\n      end\n    end\n\n    class Caution \u003c Moody::State\n      def color\n        \"yellow\"\n      end\n\n      def next\n        sleep 1\n        switch_to Stop\n      end\n    end\n\n    class TrafficLight\n      extend  Moody::Context\n\n      initial_state Stop\n      delegate_to_state :color, :next\n    end\n\n    traffic_light - TrafficLight.new\n\n    loop do\n      puts traffic_light.color\n      traffic_light.next\n    end\n\nCallbacks\n---------\n\nAs you can see from the example above, Moody also provides callbacks when\nentering and leaving a state. If your state classes define instance methods\n`enter` and `leave`, then they will be called at the appropriate times.\n\nInspiration\n-----------\n\nThis is a reimplementation of the State Pattern gem by Daniel Cadenas. Check out\nhis implementation at [his repository](http://github.com/dcadenas/state_pattern).\n\nInstalling\n----------\n\n    gem install moody\n\nContributing\n------------\n\n* Send a pull request.\n* Small, atomic commits, please.\n* Make sure to add tests.\n* Bonus points if you add features on topic branches.\n\nLicense\n-------\n\nCopyright Nicolás Sanguinetti \u003chi@nicolassanguinetti.info\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoca%2Fmoody","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoca%2Fmoody","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoca%2Fmoody/lists"}