On Mar 21, 10:08 am, Nels Nelson <[email protected]> wrote:
> On Mar 20, 3:08 pm, Jeremy Evans <[email protected]> wrote:
>
> > Is there a reason you are not able to provide correct
> > parameters when the model class is defined?
>
> The dataset is not known when the model class is defined because I
> cannot define classes inside of a method, and I am attempting to
> programmatically automate the tear-down and build-up of the database
> and database schema.  For instance:https://gist.github.com/879582

First, your models should not be involved in the tear-down or setup of
the database or database schema.  I see from your gist that's not how
you are using them, you just want them loaded at a specific point.

Looking at your gist, the easiest way to handle things would be to
define the schema correctly the first time, define your models, then
rebuild the schema for each test: https://gist.github.com/879901

If your are using a database that supports transactional schema
modifications, such as PostgreSQL, you can just run each test case
inside a database transaction.

> To work around this, I would have to do either of two things: 1.) Run
> at least two separate processes in order -- one responsible for
> database+schema setup/tear-down routines, and another responsible for
> defining the model class(es), specifying the dataset(s), and test
> execution; 2.) After database+schema setup/tear-down, require a
> separate source file defining the model class(es), datasets, and
> plugins.

Defining the schema correctly up front, then the models, will fix the
issue even if you have to reload the schema later, as long as you are
reloading the schema to be the same as it was when the models were
originally defined.

> I would like to have both set of routines available in one require-
> able file, and execute them all at once.  This would simplify the
> program structure, and make it easier for me to create single
> executable ruby scripts that are capable of performing database demos
> like the one in the gist.

The technique in my gist should handle that.

> I was looking at the source code for the Sequel::Model(source) method
> in model.rb, and it appears that I will have to override this method
> somehow, so that if a model class is defined without a dataset
> explicitly specified, then it will do nothing except allow the class
> to be defined.   If this can be accomplished then it appears that I
> should be able define the dataset for the model at my discretion.  I
> would prefer to override the Sequel code as little as possible, but it
> appears my preferences are at odds with Sequel's preferences.  :-)

I think with the technique in my gist, you won't need to worry about
that. :)

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to