class DataSeeder::Loader::JSON

Public Instance Methods

load(io) click to toggle source
# File lib/data_seeder/loader/json.rb, line 7
def load(io)
  json = ::JSON.parse(io.read)
  if json.kind_of?(Hash)
    json.each do |key, attr|
      attr[self.key_attribute] = key if self.key_attribute
      save(attr)
    end
  else
    Array(json).each { |attr| save(attr) }
  end
end