Sha256: 60c48260be3412fa4b4e85b2320f05fd3f9af75d8cf2574ba1fd7f4b63f8982e
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
module Databasion class LoadData @@config = nil def self.config=(config) @@config = config end def self.config @@config end def self.run(opts) Databasion.set_ar_logger Databasion::LOGGER.info "Updating from YAML..." models = Dir[opts[:env] + "/" + @@config['output']['migrations']['models'] + "/*.rb"].each { |file| load file } models.each do |model| f = model.split('/') normal_name = f[f.size-1].split(".")[0] plural_name = normal_name.pluralize camel_name = normal_name.camelize Databasion::LOGGER.info "Loading %s into database..." % camel_name begin yaml_file = YAML.load_file('%s/%s.yml' % [opts[:env] + "/" + @@config['output']['yaml_path'], plural_name]) rescue yaml_file = YAML.load_file('%s/%s.yml' % [opts[:env] + "/" + @@config['output']['yaml_path'], normal_name]) end for row in yaml_file['data'] klass = eval("%s.new" % camel_name) model = camel_name.constantize.find(:first, :conditions => ['id = ?', row['id']]) if model camel_name.constantize.update(model.id, row) else klass.id = row['id'] klass.update_attributes(row) end end if yaml_file['data'] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
databasion-0.2.0 | lib/databasion/load_data.rb |