Giter Site home page Giter Site logo

undeletable's Introduction

Build Status Gem Version

Undeletable

undeletable on the model class disables the ability to delete/destroy on instance, model class, and via relation, using the default ActiveRecord version of those, and supports destroy callbacks if raise not enabled. undeletable! on the model class will raise an error when those are attempted. destroy! in Rails 4 is supported.

Tested with ActiveRecord 3.1.x, 3.2.x, and 4.0.x via travis and appraisal.

Code originally based on Paranoia (by Ryan Bigg and others), but extremely modified to the point it really shares little in common now.

Installation & Usage

Put this in your Gemfile:

gem 'undeletable'

Then run:

bundle install

Updating is as simple as bundle update undeletable.

Usage

In your environment.rb:

Undeletable.configure do
  # if true, debug log failed attempts to delete/destroy when not raising error
  self.debug = false
end

...

In your model:

To silently disallow attempts to delete/destroy:

class Client < ActiveRecord::Base
  undeletable

  ...
end

To disallow attempts to delete/destroy, but raise ActiveRecord::ReadOnlyRecord on attempts:

class Client < ActiveRecord::Base
  undeletable!

  ...
end

Upgrading

  • v0.0.1 -> v1.0.x: delete! and destroy! no longer supported for now. destroy! has a Rails 4 naming conflict with same named method, and attempting to provide support for ActiveRecord::Relation made it too complicated for now (problems with infinite recursion requiring more state to setup and check, etc.). If you need to delete or destroy an undeletable model, the workaround is to comment the undeletable method on the class.

License

This gem is released under the MIT license.

undeletable's People

Contributors

garysweaver avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.