Class: DataSeeder::Loader::Txt
- Inherits:
-
Object
- Object
- DataSeeder::Loader::Txt
- Includes:
- DataSeeder::Loader
- Defined in:
- lib/data_seeder/loader/txt.rb
Instance Attribute Summary collapse
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
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, #log_destroy, #log_indent, #log_save, #log_update, #model_info, #process, #save, #save_model, #setup, #teardown
Instance Attribute Details
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
6 7 8 |
# File 'lib/data_seeder/loader/txt.rb', line 6 def line_number @line_number end |
Instance Method Details
#load(io) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/data_seeder/loader/txt.rb', line 8 def load(io) if method = config[:line] @line_number = 0 io.each_line do |line| begin @line_number += 1 next if line.blank? || line.match(/^\s*#/) save(method.call(line)) rescue Exception => e logger.error "Exception at line #{@line_number}: #{e.}" raise unless config[:continue_on_exception] end end else raise "No line method defined for #{self.klass.name}" end end |