merged/config/initializers/active_file.rb

28 lines
501 B
Ruby
Raw Normal View History

2022-12-11 20:30:25 +01:00
require "active_hash"
2022-12-22 15:58:51 +01:00
module ActiveYaml
2022-12-11 20:30:25 +01:00
Base.class_eval do
2022-12-22 15:58:51 +01:00
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
2022-12-11 20:30:25 +01:00
def self.delete(id) # only works with id's
@record_index.delete(id.to_s)
@records.delete_if{|record| record[:id] == id.to_i}
true
end
2022-12-11 20:44:52 +01:00
def self.the_private_records
2022-12-11 20:30:25 +01:00
@records
end
end
end