lwe/simple_enum — pull request #86 by bbtfr (2014-09-14 04:19:43+00:00)
Title: add multi-select support

Sometimes, we need multi-select enum support.

At first, I tried to do it by writing a accessor, but I found that if I did it in that way, I had to write `multiple_accessor`, `multiple_ignore_accessor`, `multiple_whiny_accessor` 3 accessors to handle accessor problems, and I think that is not DRY.

So in this PR, I decided to create a `SimpleEnum::Enums` module, just like `SimpleEnum::Accessors` and Hashers, and it will create `SimpleEnum::Enums::Enum` or `SimpleEnum::Enums::MultiEnum` depending on if there is a `:multiple` option passed by.

So the following code will work:
```ruby
class User < ActiveRecord::Base
as_enum :favorites, iphone: 0, ipad: 1, macbook: 2, multiple: true
end

jane = User.new
jane.favorites = [:iphone, :ipad]
jane.iphone? # => true
jane.ipad? # => true
jane.macbook? # => false
jane.favorites # => [:iphone, ipad]
jane.favorite_cds # => [0, 1]

joe = User.new
joe.iphone! # => [:iphone]
joe.favorites # => [:iphone]
joe.favorite_cds # => [0]

User.favorites # => #
User.favorites[:iphone] # => [0]
User.favorites.values_at(:iphone, :ipad) # => [0, 1]
User.iphones # Now raise an error cause (WHERE favorite_cds = 0) doesn't work
```

And `favorite_cds` should be create manually, eg:
```ruby
serialize favorite_cds, Array
```
The second argument of `serialize` method can be a coder instance will have `dump` & `load` 2 methods, [like default YAML Serializer](https://github.com/rails/rails/blob/master/activerecord/lib/active_record/coders/yaml_column.rb). So I think we could serialize multi-select enums by writing some coder class, eg: bitwise or use join table & remote keys

I think this PR changes a lot, and not been fully tested (through I have write some tests, but I think we need more), it just an idea that maybe can be added in SimpleEnum 3.0.