Class: DataSeeder::Loader::YAML
- Inherits:
-
Object
- Object
- DataSeeder::Loader::YAML
- Includes:
- DataSeeder::Loader
- Defined in:
- lib/data_seeder/loader/yaml.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
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |