lib/data_loader.rb
def load_file(key)
    puts "load_file(#{key})" if ENV['DEBUG']
    fileinfo = self[key]
    raise RuntimeError, 'Unable to locate file #{name}' unless fileinfo
    
    return if fileinfo[:state] == :loaded # Done if this file is already loaded

    # Load model dependencies if the file name corresponds to a model
    model_name = key.to_s.classify
    klass = model_name.constantize rescue nil
    @owner.model_depends(klass) if klass && klass.ancestors.include?(ActiveRecord::Base)
    
    # Now do the actual load
    puts "Request load of #{key}" if ENV['DEBUG']
    case fileinfo[:type] 
    when '.yml', '.csv'
      ActiveRecord::Base.connection.purge_data(key.to_s)
      Fixtures.create_fixtures( File.dirname(fileinfo[:path]), key.to_s)
    when '.rb'
      puts "#{key} instance eval" if ENV['DEBUG']
      @owner.instance_eval(IO.read(fileinfo[:path]), fileinfo[:path])
    else
      raise RuntimeError, "Improper file extension load requested #{fileinfo[:path]}"      
    end
    
    # Mark file as loaded
    puts "loaded file #{fileinfo[:path].gsub(@data_root, '')}"
    fileinfo[:state] = :loaded
   end
# Load a file given the symbolic key for the base name.
Load a file given the symbolic key for the base name.
Load a file given the symbolic key for the base name .
def load_file(key)
    puts "load_file(#{key})" if ENV['DEBUG']
    fileinfo = self[key]
    raise RuntimeError, 'Unable to locate file #{name}' unless fileinfo
    return if fileinfo[:state] == :loaded 
    model_name = key.to_s.classify
    klass = model_name.constantize rescue nil
    @owner.model_depends(klass) if klass && klass.ancestors.include?(ActiveRecord::Base)
    puts "Request load of #{key}" if ENV['DEBUG']
    case fileinfo[:type] 
    when '.yml', '.csv'
      ActiveRecord::Base.connection.purge_data(key.to_s)
      Fixtures.create_fixtures( File.dirname(fileinfo[:path]), key.to_s)
    when '.rb'
      puts "#{key} instance eval" if ENV['DEBUG']
      @owner.instance_eval(IO.read(fileinfo[:path]), fileinfo[:path])
    else
      raise RuntimeError, "Improper file extension load requested #{fileinfo[:path]}"      
    end
    puts "loaded file #{fileinfo[:path].gsub(@data_root, '')}"
    fileinfo[:state] = :loaded
   end
def load_file ( key ) puts "load_file(#{key})" if ENV [ 'DEBUG' ] fileinfo = self [ key ] raise RuntimeError , 'Unable to locate file #{name}' unless fileinfo return if fileinfo [ :state ] == :loaded model_name = key . to_s . classify klass = model_name . constantize rescue nil @owner . model_depends ( klass ) if klass && klass . ancestors . include? ( ActiveRecord :: Base ) puts "Request load of #{key}" if ENV [ 'DEBUG' ] case fileinfo [ :type ] when '.yml' , '.csv' ActiveRecord :: Base . connection . purge_data ( key . to_s ) Fixtures . create_fixtures ( File . dirname ( fileinfo [ :path ] ) , key . to_s ) when '.rb' puts "#{key} instance eval" if ENV [ 'DEBUG' ] @owner . instance_eval ( IO . read ( fileinfo [ :path ] ) , fileinfo [ :path ] ) else raise RuntimeError , "Improper file extension load requested #{fileinfo[:path]}" end puts "loaded file #{fileinfo[:path].gsub(@data_root, '')}" fileinfo [ :state ] = :loaded end
Load a file given the symbolic key for the base name.
Load a file given the symbolic key for the base name .
# Done if this file is already loaded # Load model dependencies if the file name corresponds to a model # Now do the actual load # Mark file as loaded
key