12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/models/hera_cms/application_record.rb', line 12
def update_seed
model = self.class.model_name.plural
file_name = "hera_database_seed.yml"
directory_path = File.join(Rails.root, 'db', 'hera_cms')
@file_path = File.join(directory_path, file_name)
Dir.mkdir(directory_path) unless File.exists?(directory_path)
elements = File.exists?(@file_path) ? YAML.load(File.read(@file_path)) : {}
elements[model] = {} unless elements.key?(model)
elements[model][self.identifier] = self.as_json.without("id", "created_at", "updated_at")
File.open(@file_path, "w") { |file| file.write(elements.to_yaml) }
end
|