Skip to content

Instantly share code, notes, and snippets.

@brainix
Created January 4, 2013 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainix/4449311 to your computer and use it in GitHub Desktop.
Save brainix/4449311 to your computer and use it in GitHub Desktop.
Prevent DataMapper resources from being destroyed
require 'data_mapper'
module Appends
module InstanceMethods
# This module contains methods that we'll make available as instance
# methods on DataMapper resources.
def vomit
throw :halt
end
end
end
# Make our module's methods available as instance methods on DataMapper
# resources.
DataMapper::Model.append_inclusions(Appends::InstanceMethods)
class Thing
include DataMapper::Resource
property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
# Vomit before destroy, preventing destroy.
before :destroy, :vomit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment