0.0
The project is in a healthy, maintained state
Sometimes you want to protect your models from being updated or destroyed directly. This gem provides concerns for that.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

model_guard

Gem Version Build Status Gem Downloads Maintainability

Two small concerns for ActiveRecord that can guard against direct creates, updates and destroys. Handy if you want to force the use of directing all persistence through service objects and guard against accidental CRUD operations in the console.

Installation

Include the gem in your Gemfile:

gem "model_guard"

Usage

Create / update protection

Protects against #save, #save!, #update, #update!. Instead use #guarded_save, #guarded_save!, #guarded_update, #guarded_update! or #guarded_create.

class User < ActiveRecord::Base
  include ModelGuard::CreateOrUpdateGuard
end

CreateGuardedUser.guarded_create(name: "Joe")
user.guarded_update(name: "Joe")

or

user.allow_direct_create_or_update!
user.save

Destroy protection

class User < ActiveRecord::Base
  include ModelGuard::DestroyGuard
end

Will raise an exception when calling destroy on an instance of User. Instead use guarded_destroy or guarded_destroy!.

user.guarded_destroy
user.guarded_destroy!

Support

Submit suggestions or feature requests as a GitHub Issue or Pull Request (preferred). If you send a pull request, remember to update the corresponding unit tests and/or add new tests.