Skip to content

kristianmandrup/classy_enum-mongoid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClassyEnum::Mongoid

ClassyEnum is a Ruby on Rails gem that adds class-based enumerator functionality to model attributes. This adaptor works with Mongoid v2.1.0+

Installation

Add this line to your application's Gemfile:

gem 'classy_enum-mongoid'

And then execute:

$ bundle

Or install it yourself as:

$ gem install classy_enum-mongoid

Usage

See the ClassyEnum README for documentation and usage examples.

Custom fields

You can either use the Enum class as a Custom Mongoid field with serialization support using mongoize/demongoize and evolve support for searches.

class AllowBlankBreedDog
  include Mongoid::Document

  field :breed, type: Breed, :enum => {:allow_blank => true}
end

Or you can use the classy_enum_field macro to create the enum field in a more shorthand way.

class AllowNilBreedDog
  include Mongoid::Document
  
  classy_enum_field :breed, :allow_nil => true
end

Enjoy :)

PS: See the spec/adapter_spec.rb file for more details.

Copyright

Copyright (c) 2012 Peter Brown. See LICENSE for details.

About

Mongoid Adaptor for ClassyEnum

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%