No commit activity in last 3 years
No release in over 3 years
Enum mapper for Mongoid field
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.15
~> 5.0
>= 3.5.1, ~> 3.5
~> 10.0

Runtime

<= 6.2.1
 Project Readme

Gem Version Maintainability Test Coverage Build Status

Mongoid Enum Mapper

Inspired by ActiveRecord::Enum, the library supports a lightweight solution to map enum key value

Installation

Add this line to your application's Gemfile:

gem 'mongoid_enum_mapper'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mongoid_enum_mapper

Usage

# Allow Mongoid to have ActiveRecord like Enum type of Mapping

#=> OrderDelivery.rb Model
include Mongoid::EnumMapper
define_enum :status, { pending: 0, shipping: 1, shipped: 2 }

# Examples
od = OrderDelivery.new
od.status             #=> Default :pending
od.status = :shipping #=> :shipping
od.status             #=> :shipping
od[:status]           #=> 1

od.status = :invalid  #=> :invalid
od.status             #=> :shipping

od.update(status: :pending)
od.status             #=> :pending

OrderDelivery::STATUS #=> { pending: 0, shipping: 1, shipped: 2 }
OrderDelivery.update_all(OrderDelivery::STATUS[:shipping])

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/berniechiu/mongoid_enum_mapper.

License

The gem is available as open source under the terms of the MIT License.