beerlington/classy_enum — Issue #9: Issue on 3.1.3 with loading of class constants and subdirectories
Author: synth
Created: 2011-12-16 23:09:52+00:00
State: open

Hey,

Originally, I had my enums all in one file. However, this caused a problem in dev env because classes would be reloaded but not the subclasses. I think this is because rails only reloads based upon file names and doesn't know there are more classes defined in that file.

So I moved the sub enums into app/models/job_types/. JobType is my enum class and added app/models/job_types to the autoload directory in application.rb

However, this still causes more problems because the subclasses are still not loaded at all. However, the class constants are there because of the behavior in class_methods.rb#enum_classes methods where a class constant is assigned.

So my theory is that when rails goes to load the file, it sees an existing class constant for the file and skips loading of the file.

Interestingly, if I namespace the enum to the name of the directory, job_type...so classes are defined as JobType::JobTypeWebsite < JobType, and I access it JobType::JobTypeWebsite, it works.

The assigning of the class constant should optional.

I'm going to fork this repo and work on it and get back to you.