What's a good way to specify set of records to be created across multiple models (with associations)

Hi,

I need to be able to specify for my application, via a configuration
approach (i.e. power user, no nice UI required), a way to automate
creation
of a pre-determine set of database records across a few models. So
I’ll
try to explain as best I can:

  • Assume I have a model hierarchy something like the following
    (basically
    allocating a back account item out):
  • model “Bank Account Item” can have multiple
  • model "Allocation"s and within each allocation it defines
    .amount (for the allocation, total for each allocation needs to equal
    bank_account)
    .person_id (link to existing person in the Person table/model)
    .category_id (link to existing category in the Category table/model)
  • There will be an automation routine that will say, “if you see a bank
    account item with a description of XYZ, then automatically set up it’s
    allocation to People & Categories” (i.e. predefined). This could be as
    simple as an “Automation” model that has a regex that would be used, and
    then a string to store the association(s) that should be created (e.g.
    XML,
    or YAML, or Ruby code, i.e. the reason for the question).

  • An example for what this string might represent for say an automation
    record where the regex was “Telephone Bill” might be:
    --------example---------

  • Association 1

  • amount = 30% (calculates absolute amount on the fly)
  • person_id = 1 <Person A’s id>
  • category_id = 23
  • Association 2
  • amount = 70% (calculates absolute amount on the fly)
  • person_id = 1 <Person A’s id>
  • category_id = 3
    --------example---------

Any suggestions re (a) a nice generic way to do this and (b) what format
may
be the best (e.g. XML, Ruby code, YAML).

Some ideas that come to mind:
[1] Ruby code that takes input (not great)
[2] Ruby code that describes “example” above in the form of Array or
Hashes.
Maybe best?
[3] XML - readable, but a little more code to import?
[4] YAML - not that readable, but easy to import
[4] Other?

thanks


Greg
http://blog.gregnet.org/

On Mon, Jan 12, 2009 at 5:10 PM, Greg H.
[email protected] wrote:

I need to be able to specify for my application, via a configuration
approach (i.e. power user, no nice UI required), a way to automate creation
of a pre-determine set of database records across a few models. So I’ll
try to explain as best I can:

Can’t remember the library names… but you want to look for a
“factory” of some sort.

Rails, RSpec and Life blog…

I’m more interested in how the routine (albeit in a Factory or not
works)
actually - e.g. best way of storing the info: xml, ruby code, yaml??

On Mon, Jan 12, 2009 at 9:04 PM, Mikel L. [email protected]
wrote:

“factory” of some sort.


http://lindsaar.net/
Rails, RSpec and Life blog…


Greg
http://blog.gregnet.org/