This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "active_record" | |
require 'active_record/errors' | |
module ActiveRecord | |
class ProtectedModelError < ActiveRecordError #:nodoc: | |
def initialize | |
super("Cannot delete record because its protected") | |
end | |
end | |
module ProtectedModel | |
extend ActiveSupport::Concern | |
protected | |
def delete(*args) | |
raise ProtectedModelError.new | |
end | |
def destroy_all(*args) | |
raise ProtectedModelError.new | |
end | |
def destroy(*args) | |
raise ProtectedModelError.new | |
end | |
module ClassMethods | |
def delete_all(*args) | |
raise ProtectedModelError.new | |
end | |
end | |
end | |
end | |
class Query < ActiveRecord::Base | |
include ActiveRecord::ProtectedModel if Rails.env.production? | |
end |
No comments:
Post a Comment