Class: DataSeeder::SeedFile
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DataSeeder::SeedFile
- Defined in:
- app/models/data_seeder/seed_file.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.file_hash ⇒ Object
5 6 7 8 9 10 11 |
# File 'app/models/data_seeder/seed_file.rb', line 5 def self.file_hash hash = {} all.each do |seed_file| hash[seed_file.path] = seed_file end hash end |
.load(path) ⇒ Object
13 14 15 16 |
# File 'app/models/data_seeder/seed_file.rb', line 13 def self.load(path) seed_file = self.file_hash[path] || new(path: path) seed_file.load end |
Instance Method Details
#load ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/data_seeder/seed_file.rb', line 18 def load new_sha256 = Digest::SHA256.file(path).hexdigest if self.sha256 != new_sha256 self.sha256 = new_sha256 ext = File.extname(self.path)[1..-1] return unless ext loader = DataSeeder.config.loaders[ext] unless loader DataSeeder.logger.info { "Warning: No loader for #{path}"} return end loader.process(path) save! end end |