Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whats the status on this gem? #46

Open
noiseunion opened this issue Oct 3, 2017 · 20 comments
Open

whats the status on this gem? #46

noiseunion opened this issue Oct 3, 2017 · 20 comments

Comments

@noiseunion
Copy link

Just looking through and noticing that there has not been a commit in 2 years, and PRs that seem to have been ignored for some time as well. Does this gem need new maintainers? Is there an alternative people have switched to?

@jafuentest
Copy link

Seems pretty much dead, have you found any alternatives?

@flvrone
Copy link

flvrone commented Dec 18, 2017

@jafuentest this one seems to be fresher: https://github.com/amw/mongoid_enum

@noiseunion
Copy link
Author

@FunkyloverOne @jafuentest - unfortunately that one also looks to be dead. :(

amw/mongoid_enum#1

@rmm5t
Copy link

rmm5t commented Feb 26, 2018

It looks like the more recent pull-requests that came in for this gem all broke the build. I wouldn't blame @thetron for ignoring those.

As an attempt at rejuvenating this project, I just submitted 4 new pull-requests that all together bring things back up to snuff while also adding Mongoid 6 support. Oh, and they run green too. 💚

@thetron If you have the time to review these pull-requests and publish a new release of mongoid-enum to rubygems, that would be super awesome! Hopefully, these pull-requests make your life a bit easier. Thanks!

@CyberMew
Copy link

CyberMew commented May 3, 2018

Looks like Mongoid 7 was released last month, I hope this gem can be updated, enums are really very useful!

@flvrone
Copy link

flvrone commented May 3, 2018

Guys, you can switch to enumerize, it works well with Mongoid 6.4 for me, guess it will also work for Mongoid 7.

@douglaslise
Copy link

Since this gem does not get updated by three years I wrote a new gem called mongoid_enumerable, which is compatible with MongoId since version 4 until 7: https://github.com/douglaslise/mongoid_enumerable

@kenneth1870
Copy link

Hi, @rmm5t Why do not we make a fork do we maintain this or do we create our own gem? I have had many problems and I would like to help solve them. 👍

@rmm5t
Copy link

rmm5t commented Aug 14, 2018

@kenneth1870 I'm not a huge fan of forking open source projects for reasons such as this unless all other options are exhausted, but I understand your frustration.

However, in the meantime, I just created a working branch (with all my other branches merged into it) in my repository that you're welcome to try and work against until this repository is updated.

  gem "mongoid-enum", github: "rmm5t/mongoid-enum", branch: "working"

@thetron If you need help maintaining this project, I'm willing to help get this repository up to snuff and help publish a new gem to rubygems. Feel free to review my github and rubygem history.

@kenneth1870
Copy link

Thanks @rmm5t that works for me

@daniloakamine
Copy link

@rmm5t it looks great, but could you update the branch to support mongoid 7.0.2, please?

@daniloakamine
Copy link

I've just found this project: https://github.com/lwe/simple_enum
I haven't tested yet, but it has a lot of contributors and seems very active.

@flvrone
Copy link

flvrone commented Jan 22, 2019

BTW I can confirm that I use https://github.com/brainspec/enumerize with Mongoid 7 in production

@rmm5t
Copy link

rmm5t commented Jan 22, 2019

@daniloakamine I haven't touched the project that relied on this particular pull-request in a while now, but I'll probably be near that codebase in the next couple weeks or so. If I find the time, I'll add another PR to allow mongoid 7, but no promises. Considering these PRs aren’t being reviewed or merged, it might be better to consider alternative gems as necessary.

@daniloakamine
Copy link

@rmm5t well, let it go.
I'll try other libraries like simple_enum or what @FunkyloverOne said.
Thanks anyway.

@mltsy
Copy link

mltsy commented Jan 24, 2019

I'm working on migrating an app from this gem to enumerize (which seems to be the most widely used and supported enum library that supports MongoID), and the transition is tedious, but fairly simple if you know the sticking points, so I thought I'd share in case anybody else needs to do this:

  1. replace the 'mongoid-enum' gem with the 'enumerize' gem
  2. replace include Mongoid::Enum with extend Enumerize
  3. Here's the trick - replace:
    enum :field_name, [:option1, :option2, :option3]
    
    with:
    field :_field_name, as: :field_name
    enumerize :field_name, in: [:option1, :option2, :option3], default: :option1, predicates: true
    validates_presence_of :field_name
    
    or replace:
    enum :field_name, [:option1, :option2, :option3], default: nil, required: false
    
    with:
    field :_field_name, as: :field_name
    enumerize :field_name, in: [:option1, :option2, :option3], predicates: true
    
  4. Also if you use mongoid-enum's constants (FIELD_NAME) anywhere, replace them with Model.field_name.values, or define the constants yourself

The differences to remember are:

  1. Validation of nil values:
    • mongoid-enum fields are required by default (nil is not allowed)
    • enumerize fields are not (nil is allowed) - you can validates_presence_of :field as usual to make it a required field
  2. Default value:
    • mongoid-enum uses the first defined value as a default
    • enumerize uses nil - you can set the default option on the field declaration to change it.
    • WARNING: you can also set the default on the enumarize declaration, but be aware that doing so causes your model to always have a value (even if you save it as nil, the next time you load it, it will be back to the default, so there's no way to effectively save a nil value)
  3. Field Names:
    • mongoid-enum prefixes the field with an underscore when storing (:role => :_role)
    • enumerize does not (because... why?) 😉
  4. Root-level predicate methods:
    • mongoid-enum defines them for each enum value (enum :color, [:black, :white] => object.black?)
    • enumerize has an option for this that you enable manually if you want it (predicates: true)
    • Note: enumerize values do handle object.color.black? by default (just not object.black?)
  5. Constants
    • mongoid-enum defines a constant for every enum (enum :roles, [:user, :admin] => ROLES = [:user, :admin])
    • enumerize doesn't - but you can call User.role.values instead (or define a constant with it)
  6. Default value type
    • mongoid-enum returns symbols for all enum values by default
    • enumerize returns Enumerize::Value instances (which return equality for both strings and symbols, and respond to predicate methods)
    • WARNING: Equality for symbols and Enumerize::Values is not symmetrical. User.role == :admin may be true, but :admin == User.role returns false! This is likely to break a lot of your specs. See a this issue/workaround in the enumarize repo.
  7. Finally, separation of concerns:
    • mongoid-enum combines field definition and enum definition/validation into a single call
    • with enumerize, you use mongoid to define the field as usual, then call enumerize to add enum handling and validations.

There are other added conveniences that may allow you to clean up your code - for instance, enumerize integrates with rails_admin automatically, so you can remove custom enum code for rails_admin, but for the most part everything else works the same.

@flvrone
Copy link

flvrone commented Jan 25, 2019

Also please keep in mind this issue guys: brainspec/enumerize#333
Until it's fixed you better use this gem from master branch. You could also put a thumbs up on that one to make it more noticeable :)

@valentinbotog
Copy link

Hey guys, I have a question related to enumerize gem, We upgraded all app stacks and we are using mongoid 7, and we had to change from mongoid-enum to enumerize, and we have a problem related to multiple enumerize. The problem is no matter how I use the field + enjumerize syntax I do not have the old values which are in the DB, even after I do a mongorestore the values are not saved in field.
Enumerize:
field :_permissions, type: Array
enumerize :_permissions, in: [:no_view, :view_only, :view_and_update, :full_access],
multiple: true,
default: [:no_view], predicates: true
alias_method :permissions, :_permissions
Field : "_permissions"=>#<Mongoid::Fields::Standard:0x0000561f018ba8a0 @name="_permissions", @options={:default=>[:no_view], :type=>Array, :klass=>AccountPermission}, @Label=nil, @default_val=[:no_view], @pre_processed=true, @type=Array>
Value: _permissions: []
Mongoid-enum:
enum :permissions, [:no_view, :view_only, :view_and_update, :full_access],
multiple: true,
default: [:no_view]
Field: "_permissions"=>#<Mongoid::Fields::Standard:0x0055e0c6324fe0 @name="_permissions", @options={:type=>Array, :default=>[:no_view], :klass=>AccountPermission}, @Label=nil, @default_val=[:no_view], @pre_processed=true>
Value: _permissions: :full_access

Is there something that I missed when I changed the model field attributes from enum to enumerize?
Thank you in advance.

@jafuentest
Copy link

@valentinbotog You'll have better chances of getting a reply on the enumerize page. I found it much simpler to migrate to mongoid_enumerable.
Also, try to format your code the next time ;)
like this

@valentinbotog
Copy link

@jafuentest - thanks, I added the same comment on enumerize github page yesterday, still waiting for an example of how to use multiple and have the values from mongorestore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants