Class: DataSeeder::Loader::JSON
- Inherits:
-
Object
- Object
- DataSeeder::Loader::JSON
- Includes:
- DataSeeder::Loader
- Defined in:
- lib/data_seeder/loader/json.rb
Instance Attribute Summary
Attributes included from DataSeeder::Loader
#config, #key_attribute, #klass, #logger, #path, #path_minus_ext
Instance Method Summary collapse
Methods included from DataSeeder::Loader
#call_config, #call_method, #default_config, #destroy_model, #destroy_models, #initialize, #line_number, #log_destroy, #log_indent, #log_save, #log_update, #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 |