move saves into baes class

This commit is contained in:
2022-12-22 16:58:51 +02:00
parent a0b58fdc2f
commit fc611ce5c4
5 changed files with 12 additions and 40 deletions

View File

@ -1,8 +1,19 @@
require "active_hash"
module ActiveHash
module ActiveYaml
Base.class_eval do
def save
super
self.class.save_all
end
def self.save_all
data = @records.collect {|obj| obj.attributes}
File.write( self.full_path , data.to_yaml)
self.reload
end
def self.delete(id) # only works with id's
@record_index.delete(id.to_s)
@records.delete_if{|record| record[:id] == id.to_i}