Class: Jason::Encoding::PersistenceHandler::Deletable
- Inherits:
-
PersistenceObject
- Object
- PersistenceObject
- Jason::Encoding::PersistenceHandler::Deletable
- Includes:
- Operations::File
- Defined in:
- lib/jason/encoding/deletable.rb
Instance Attribute Summary
Attributes inherited from PersistenceObject
Instance Method Summary collapse
Methods inherited from PersistenceObject
#eigenclass, #initialize, #instance_method
Constructor Details
This class inherits a constructor from Jason::Encoding::PersistenceHandler::PersistenceObject
Instance Method Details
#delete ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jason/encoding/deletable.rb', line 11 def delete deleted = true persisted_file_content = load_from_file(where_to_persist) r_objects = ActiveSupport::JSON.decode(persisted_file_content) r_objects.delete_if{|obj| obj[@root]["id"] == @persistable_obj.send(:id)} save_to_file(ActiveSupport::JSON.encode(r_objects)) rescue deleted = false ensure return deleted end |