paranoid_model 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/lib/paranoid_model.rb +35 -0
- data/lib/paranoid_model/version.rb +3 -0
- data/paranoid_model.gemspec +18 -0
- data/spec/paranoid_model_spec.rb +24 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 36575d181815cf53aafbb5c9118ba01634373c79
|
4
|
+
data.tar.gz: fc1750913615565daac6795b59623760d5516d32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 191f4ff18f22da0b27ec0930e28ce8603d9af0e5741610ddb22d6b0a01007f759e753087d33e468984f11de6455680977474c35571da07a1c269b766809d1d5e
|
7
|
+
data.tar.gz: 69c9272d0c05dd03410194dab192ea40dac134d74a480c1b6ddcf5771ebf77cdd362334b959a93e1be7d076f7b87aee71bf4ac4f739e056ad96d1a8a6d4f5f05
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tijmen Brommet
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# ParanoidModel
|
2
|
+
|
3
|
+
Will block you from deleting an ActiveRecord model by calling `model.delete`, `model.destroy` `Class.delete_all` and `Class.destroy_all`.
|
4
|
+
|
5
|
+
Also disables `Class.update_all` and `model.update_attribute`, because they have no validations.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'paranoid_model', github: 'tijmenb/paranoid_model'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
class SomeSensitiveModel < ActiveRecord::Base
|
19
|
+
include ParanoidModel
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
```console
|
24
|
+
> SomeSensitiveModel.destroy_all
|
25
|
+
ParanoidModel::ParanoidModelException: :destroy_all is verboten for this model.
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
1. Fork it
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "paranoid_model/version"
|
2
|
+
|
3
|
+
module ParanoidModel
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
class ParanoidModelException < StandardError; end
|
9
|
+
|
10
|
+
def update_attribute(*)
|
11
|
+
raise ParanoidModelException, ":update_attribute is verboten for this model."
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroy(*)
|
15
|
+
raise ParanoidModelException, ":destroy is verboten for this model."
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(*)
|
19
|
+
raise ParanoidModelException, ":delete is verboten for this model."
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
def update_all(*)
|
24
|
+
raise ParanoidModelException, ":update_all is verboten for this model."
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy_all(*)
|
28
|
+
raise ParanoidModelException, ":destroy_all is verboten for this model."
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete_all(*)
|
32
|
+
raise ParanoidModelException, ":delete_all is verboten for this model."
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/paranoid_model/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Tijmen Brommet"]
|
6
|
+
gem.email = ["tijmen@gmail.com"]
|
7
|
+
gem.description = %q{Disable sensitive methods on ActiveRecord models}
|
8
|
+
gem.summary = %q{Disables destructive methods and methods that don't validate the input on ActiveRecord models}
|
9
|
+
gem.homepage = "https://github.com/tijmenb/paranoid_model"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "paranoid_model"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ParanoidModel::VERSION
|
17
|
+
gem.add_development_dependency "rspec"
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'paranoid_model'
|
2
|
+
|
3
|
+
class ActiveRecordTestClass
|
4
|
+
include ParanoidModel
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ParanoidModel do
|
8
|
+
|
9
|
+
describe 'instance methods' do
|
10
|
+
%w[update_attribute destroy delete].each do |method_name|
|
11
|
+
it "raises exception for :#{method_name}" do
|
12
|
+
expect { ActiveRecordTestClass.new.send method_name }.to raise_error(ParanoidModel::ParanoidModelException)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'class methods' do
|
18
|
+
%w[update_all destroy_all delete_all].each do |method_name|
|
19
|
+
it "raises exception for :#{method_name}" do
|
20
|
+
expect { ActiveRecordTestClass.send method_name }.to raise_error(ParanoidModel::ParanoidModelException)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paranoid_model
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tijmen Brommet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Disable sensitive methods on ActiveRecord models
|
28
|
+
email:
|
29
|
+
- tijmen@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- .travis.yml
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/paranoid_model.rb
|
41
|
+
- lib/paranoid_model/version.rb
|
42
|
+
- paranoid_model.gemspec
|
43
|
+
- spec/paranoid_model_spec.rb
|
44
|
+
homepage: https://github.com/tijmenb/paranoid_model
|
45
|
+
licenses: []
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.0.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Disables destructive methods and methods that don't validate the input on
|
67
|
+
ActiveRecord models
|
68
|
+
test_files:
|
69
|
+
- spec/paranoid_model_spec.rb
|
70
|
+
has_rdoc:
|