On Saturday, April 28, 2012 11:07:20 AM UTC-7, Johnny wrote:
 

> How can I extend Sequel::Model? Every Sequel::Model subclass requires 
> a table, but I want all the models in my application to inherit from 
> one class, which won't have a backing table. How can I do this? 
>

Even though it's an unsupported use, subclassing Sequel::Model works quite 
well if you're careful. I do it in several projects in which I want to use 
Sequel::Model, but I can't know where the database is until runtime (e.g., 
connect info is in a config file, etc.). One example is the 'mongrel2' gem, 
which uses it for interacting with Mongrel2's config database:

  https://github.com/ged/ruby-mongrel2/blob/master/lib/mongrel2/config.rb

I also use it in the 'wordnet' library, which connects to a (again, unknown 
until runtime) database that contains the WordNet lexicon:

  https://github.com/ged/ruby-wordnet/blob/master/lib/wordnet/model.rb

It can be tricky to manage if you're using two different subclasses of 
Sequel::Model in the same application, but as long as you hook the #db= 
method of your subclasses and reset the database for each descendent (via 
the :subclasses plugin), it seems to work fine.

That code does use some non-public information from Sequel::Model, so 
caveat emptor. Expect to have to track the Sequel changelog a little more 
closely than everyone else. Fortunately, Jeremy's changelogs are epic in 
their scope, detail, and accuracy.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/zYZ34tGoHewJ.
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