A short and sweet enumerator class for usage with ActiveRecord.
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
script
spec
.gitignore
.ruby-version
.travis.yml
Gemfile
README.md
lite_enum.gemspec

README.md

lite_enum version build

A short and sweet enumerator class for usage with ActiveRecord, most likely.

Goals:

  • Concise
  • Readable
  • Useful for DOBT's stack
  • Plain ol' Ruby API
  • No auto-generation of predicate methods like in ActiveRecord::Enum

Usage

# Gemfile
gem 'lite_enum'

# app/models/foo.rb
class Foo < ActiveRecord::Base
  def self.sizes
    LiteEnum.new(:small, :medium, :large)
  end
end

Foo.sizes[1] # => :small
Foo.sizes[:small] # => 1
foo = Foo.new(size: Foo.sizes[:small])
foo.size # => 1
foo.size == Foo.sizes[:small] # => true