Class: DataSeeder::Loader::JSON

Inherits:
Object
  • Object
show all
Includes:
DataSeeder::Loader
Defined in:
lib/data_seeder/loader/json.rb

Instance Attribute Summary

Attributes included from DataSeeder::Loader

#file_config, #key_attribute, #path, #path_minus_ext

Instance Method Summary collapse

Methods included from DataSeeder::Loader

#call_file_method, #config, #initialize, #klass, #line_number, #load_file_config, #logger, #model_info, #process, #save, #save_model, #setup, #teardown

Instance Method Details

#load(io) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# 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