class DataSeeder::Loader::YAML

Public Instance Methods

load(io) click to toggle source
# File lib/data_seeder/loader/yaml.rb, line 8
def load(io)
  yaml = ::YAML.load(ERB.new(io.read).result)
  if yaml.kind_of?(Hash)
    yaml.each do |key, attr|
      attr[self.key_attribute] = key if self.key_attribute
      save(attr)
    end
  elsif yaml.kind_of?(Array)
    yaml.each { |attr| save(attr) }
  else
    raise "Don't know how to interpret #{self.path}"
  end
end