Thanks for rails admin, it's amazing.
The only small issue I have is that for the automatic enum methods (object#name_enum) it seems much cleaner to use class methods rather than instance methods.
The reason for this is when creating e.g. search forms, I want access to the enum without having to create an instance of an object. It's a pain having to create both class and instance methods for this, or creating a new object just to access the enum values.
I've attached a failing test case to describe the expected behavior, basically RA should check for Foo.color_enum as well as Foo.new.color_enum.
I'm not really sure how to go about implementing this, but happy to give it a try if you like the feature.
Please let me know if there's a better way of doing this that I'm missing.
Add failing test case for automatic class enum methods
Automatically detect class enum methods
I just added my suggested fix for this.
Basically, if the model's class responds to enum_method, it will use that instead, and fall back to the instance enum_method.
Again, if there is a better way of doing things please let me know :)
Test that enum_method can also be used to specify a class method
I added :enum because I needed it, but frankly, this is just a nice hack that saves some time, out of RailsAdmin's scope (which is about presentation of data)...
I used instance methods so that you can have 'object dynamic' proposals.
Are you sure you want that ? It doesn't add any functionality.
Well, I wish rails had a standard way of dealing with enums. But lacking a standard, I really like your way of handling it. It doesn't require an extra gem or anything, you can simply add an enum method to the model and store an int in the database.
However, it just feels like a class method makes more sense, so that it can be accessed without needing to create a new object. My implementation doesn't really change any existing functionality, it just means you can specify either a class method or instance method with your enum_method setting.
Ok, sure, let's merge!
Thanks a lot.