Dr. Nic / List ~
I've finally pushed a copy of my (now-tested) changes to
http://github.com/hypomodern/dr-nic-magic-models/tree/master
I'm certain that my code is ugly, but hey, it's got passing tests. I
had a heck of a time getting the tests it came with to pass to start
with :). But eventually pass they did -- tempramental! Testing this
stuff is harder than I expected, so any suggestions for more thorough/
less brittle tests would be awesome. I'm new to testing :).
You can blow away the magic_schema by calling {Object|
ModuleName}.clear_magic_schema -- this also unsets all the classes.
The schema will reload automatically on the next const_missing call;
you can also disable that with DrNicMagicModels.no_more_magic! if you
want to (enable with .magic!).
The repo also has support for exclusive scoping: call
DrNicMagicModels.go_exclusive to clear the base (Object) magic_schema
and make it so that the only magic you get is magic from modules, as
in:
module LocationType
magic_module :table_name_prefix => 'location_type_'
end
will still work. The magic_module call registers the calling module as
an allowable scope, basically.
Questions? Comments? Concerns?
-mhw
p.s. was a lot of fun, Dr Nic. Thanks for pushing your code to github!
On May 6, 5:50 pm, "Nic Williams" <
drnicwilli...@gmail.com> wrote:
> Looking at the code it seems that the DrNicMagicModels::Schema instance has
> its own cached @models variable with no way to reset it - two levels of
> caching! :)
> I've pushed the MM to github and won't be using SVN for it anymore. (bit my
> bit the other magicmodels sub-projects will get moved across and then I'll
> replace the SVN with a Git repo + one-branch-per-project on
rubyforge.org).
>
>
http://github.com/drnic/dr-nic-magic-models/tree/master
>
> My suggestion is to add a test case for how you'd _like_ to be able to reset
> the cache, say Module.clear_magic_schema or something; or
> Module.magic_schema.clear
> and then flesh out the code from there. That is, API first, code second.
>
> To prepare for test cases:
>
> rake mysql:build_databases
>
> rake test_mysql
>
> (or sqlite or postgresql)
>
> Keen to play? :)
>
> On Wed, May 7, 2008 at 1:40 AM, Matt Wilson <
bucket.o.nyarlatho...@gmail.com>