• E
    Refactor configs_for and friends · 4e663c1e
    eileencodes 提交于
    Moves the configs_for and DatabaseConfig struct into it's own file. I
    was considering doing this in a future refactoring but our set up forced
    me to move it now. You see there are `mattr_accessor`'s on the Core
    module that have default settings. For example the `schema_format`
    defaults to Ruby. So if I call `configs_for` or any methods in the Core
    module it will reset the `schema_format` to `:ruby`. By moving it to
    it's own class we can keep the logic contained and avoid this
    unfortunate issue.
    
    The second change here does a double loop over the yaml files. Bear with
    me...
    
    Our tests dictate that we need to load an environment before our rake
    tasks because we could have something in an environment that the
    database.yml depends on. There are side-effects to this and I think
    there's a deeper bug that needs to be fixed but that's for another
    issue. The gist of the problem is when I was creating the dynamic rake
    tasks if the yaml that that rake task is calling evaluates code (like
    erb) that calls the environment configs the code will blow up because
    the environment is not loaded yet.
    
    To avoid this issue we added a new method that simply loads the yaml and
    does not evaluate the erb or anything in it. We then use that yaml to
    create the task name. Inside the task name we can then call
    `load_config` and load the real config to actually call the code
    internal to the task. I admit, this is gross, but refactoring can't all
    be pretty all the time and I'm working hard with `@tenderlove` to
    refactor much more of this code to get to a better place re connection
    management and rake tasks.
    4e663c1e
core.rb 18.6 KB