Module: ActiveCypher::Model::Destruction
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/active_cypher/model/destruction.rb
Overview
Destruction: The module that lets you banish records from existence with a single incantation. Uses a blend of Ruby sorcery, a dash of witchcraft, and—on rare occasions—some back magick when nothing else will do.
Instance Method Summary collapse
-
#destroy ⇒ Boolean
Deletes the record from the database.
-
#destroyed? ⇒ Boolean
Returns true if this object has achieved full existential closure.
Instance Method Details
#destroy ⇒ Boolean
Deletes the record from the database. Permanently. No takesies-backsies.
Runs a Cypher ‘DETACH DELETE` query on the node. Freezes the object to prevent further use, as a kind of ceremonial burial. Because nothing says “closure” like a frozen Ruby object.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_cypher/model/destruction.rb', line 18 def destroy _run(:destroy) do raise 'Cannot destroy a new record' if new_record? raise 'Record already destroyed' if destroyed? adapter = adapter_class raise NotImplementedError, "#{adapter} does not implement Persistence" unless adapter&.const_defined?(:Persistence) if adapter::Persistence.destroy_record(self) @destroyed = true freeze true else false end end rescue StandardError => e warn "[Destruction] Destroy failed: #{e.class}: #{e.message}" false end |
#destroyed? ⇒ Boolean
Returns true if this object has achieved full existential closure. If you see this return true and the record still exists, that’s not a bug—it’s witchcraft.
41 |
# File 'lib/active_cypher/model/destruction.rb', line 41 def destroyed? = @destroyed == true |