Skip to content

lasaczka/enumancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enumancer

Gem Version   License: BSD-3-Clause

Enumancer provides a declarative, type-safe registry for named values in Ruby.
Each entry is unique by both name and value. Optional type constraints and strict mode are supported.
Designed for predictable access, JSON serialization, and clean integration into Ruby applications.


Installation

Add this line to your Gemfile:

gem 'enumancer'

Then install:

bundle install

Or install it directly:

gem install enumancer

Usage

class Status < Enumancer::Enum
  type Integer, strict: true

  entry :draft, 0
  entry :published, 1
  entry :archived, 2
end

Status[:draft].value      # => 0
Status.published.to_sym   # => :published
Status.from_json('{"name":"archived"}') # => Status.archived

Serialization

Status.draft.to_json
# => '{"name":"draft","value":0}'

Deserialization

Status.from_json('{"name":"published"}')
# => Status.published

About

Easy to use typed enums for Ruby.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages