{"id":23533373,"url":"https://github.com/necojackarc/simpler_enum","last_synced_at":"2025-04-22T22:41:40.823Z","repository":{"id":56895830,"uuid":"45919308","full_name":"necojackarc/simpler_enum","owner":"necojackarc","description":"Providing Rails like enumerated type","archived":false,"fork":false,"pushed_at":"2018-02-10T22:22:12.000Z","size":32,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-23T01:43:48.676Z","etag":null,"topics":["enum","rails","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/simpler_enum","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/necojackarc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-10T15:03:11.000Z","updated_at":"2018-02-10T23:38:42.000Z","dependencies_parsed_at":"2022-08-20T17:10:24.487Z","dependency_job_id":null,"html_url":"https://github.com/necojackarc/simpler_enum","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necojackarc%2Fsimpler_enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necojackarc%2Fsimpler_enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necojackarc%2Fsimpler_enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/necojackarc%2Fsimpler_enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/necojackarc","download_url":"https://codeload.github.com/necojackarc/simpler_enum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250337286,"owners_count":21414092,"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":["enum","rails","ruby"],"created_at":"2024-12-25T23:14:57.806Z","updated_at":"2025-04-22T22:41:40.805Z","avatar_url":"https://github.com/necojackarc.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimplerEnum\n\n[![Build Status](https://travis-ci.org/necojackarc/simpler_enum.svg?branch=master)](https://travis-ci.org/necojackarc/simpler_enum)\n[![Code Climate](https://codeclimate.com/github/necojackarc/simpler_enum/badges/gpa.svg)](https://codeclimate.com/github/necojackarc/simpler_enum)\n[![Test Coverage](https://codeclimate.com/github/necojackarc/simpler_enum/badges/coverage.svg)](https://codeclimate.com/github/necojackarc/simpler_enum/coverage)\n\nSimplerEnum provides Rails like enumerated type.\n\nIt reproduces part of [ActiveRecord::Enum](http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html) features.\n\nI hope it will help you when you want to use [ActiveRecord::Enum](http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html) in your not Rails repositories or older Rails version repositories.\n\n## Supported Ruby versions\n\n- Ruby 1.9\n- Ruby 2.x\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'simpler_enum'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install simpler_enum\n\n## Usage\n\nAny class can include `SimplerEnum` and you can define an enumerated type like this:\n\n```ruby\nrequire \"simpler_enum\"\n\nclass Person\n  include SimplerEnum\n\n  simpler_enum mood: %i(awesome excellent great good fine)\n\n  def initialize(mood: :fine)\n    self.mood = mood\n  end\nend\n```\n\nOr,\n\n```ruby\nrequire \"simpler_enum\"\n\nclass Person\n  include SimplerEnum\n\n  simpler_enum mood: {\n    awesome: 0,\n    excellent: 1,\n    great: 2,\n    good: 3,\n    fine: 4\n  }\n\n  def initialize(mood: :fine)\n    self.mood = mood\n  end\nend\n```\n\nBoth behave like this:\n\n```ruby\n[1] pry(main)\u003e Person.moods\n=\u003e {:awesome=\u003e0, :excellent=\u003e1, :great=\u003e2, :good=\u003e3, :fine=\u003e4}\n[2] pry(main)\u003e necojackarc = Person.new(mood: :awesome)\n=\u003e #\u003cPerson:0x007fd5cbbf5dd0 @mood=0\u003e\n[3] pry(main)\u003e necojackarc.awesome?\n=\u003e true\n[4] pry(main)\u003e necojackarc.excellent?\n=\u003e false\n[5] pry(main)\u003e necojackarc.great!\n=\u003e :great\n[6] pry(main)\u003e necojackarc.awesome?\n=\u003e false\n[7] pry(main)\u003e necojackarc.great?\n=\u003e true\n[8] pry(main)\u003e necojackarc.mood = :fine\n=\u003e :fine\n[9] pry(main)\u003e necojackarc.great?\n=\u003e false\n[10] pry(main)\u003e necojackarc.fine?\n=\u003e true\n[11] pry(main)\u003e necojackarc.mood = 1 # excellent\n=\u003e 1\n[12] pry(main)\u003e necojackarc.fine?\n=\u003e false\n[13] pry(main)\u003e necojackarc.excellent?\n=\u003e true\n[14] pry(main)\u003e necojackarc.mood\n=\u003e :excellent\n[15] pry(main)\u003e necojackarc.mood = \"good\"\n=\u003e \"good\"\n[16] pry(main)\u003e necojackarc.mood\n=\u003e :good\n```\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%2Fnecojackarc%2Fsimpler_enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnecojackarc%2Fsimpler_enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnecojackarc%2Fsimpler_enum/lists"}