Skip to content

netspective/active-record-seed-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

seed_data
=========

Given a hash of attributes, look up the record by an attribute in options[:SEED].

If the record with given seed keys does not exist, it is created with the rest of the options.
If the record already exists, it is updated with the given options.

Raises an exception if the record is invalid to ensure seed data is loaded correctly.

Any attribute may have "EVAL:" preceded by it and if it does, it will be evaluated at runtime
before assigning it to the ActiveRecord attribute and saving it to the database.

Returns the record.

EXAMPLE:

ModelName.create_or_update_seed(
    :SEED => { :key => "attr_1" }
    :attr_1 => val_1,
    :attr_2 => val_2
)

log = []

ModelName.create_or_update_seed(
    :SEED => { :keys => ["attr_1", "attr_2"], :log => log }
    :attr_1 => val_1,
    :attr_2 => "EVAL:some ruby code",
)

COPYRIGHT
=========

Copyright (c) 2008 Shahid N. Shah. See LICENSE for details.

About

Ruby gem and plugin that adds management of seed data to ActiveRecord

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages