protected_record 0.1.0 → 0.1.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 +4 -4
- data/README.md +26 -26
- data/lib/protected_record.rb +1 -1
- data/lib/protected_record/{user.rb → responsible_user.rb} +1 -1
- data/lib/protected_record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ee3db2399060139dabe4efb989ce1b857ee1e018
|
|
4
|
+
data.tar.gz: 34ff5f83cd940b7535ee3a28336295de5a4add6b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3f90dd864df8ae173aaeab384a2d544a3a72d5fc2f37fabea55bcbaf7dccd42824b27cb86b75e72de4c2da55b882460fa709e23c0dc8e2a8bef114ce29e7112
|
|
7
|
+
data.tar.gz: 430b1b8b46b7905d8a6179691cb51560c2d5ee931e70964cd108b4199d243d6a021e64d5f659202cb462d48ade9af35a2ec226a750e08989af12036e6f5f334a
|
data/README.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Setup for rails applications
|
|
4
4
|
|
|
5
|
-
I've created
|
|
6
|
-
|
|
5
|
+
I've created a gem called [protected_record_manager](https://github.com/rthbound/protected_record_manager)
|
|
6
|
+
to provide the necessary migrations as well as a (very) basic interface
|
|
7
|
+
for triaging `ProtectedRecord::ChangeRequest::Record` objects.
|
|
7
8
|
You are free to use this gem without the engine, but you'll need to
|
|
8
9
|
[grab these](https://github.com/rthbound/protected_record_manager/tree/master/db/migrate).
|
|
9
10
|
|
|
@@ -12,20 +13,18 @@ You are free to use this gem without the engine, but you'll need to
|
|
|
12
13
|
Prepare your models.
|
|
13
14
|
There's **two types** of models at play here:
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
2. Your records .. these are the models you want to track
|
|
17
|
-
|
|
18
|
-
So, in your models add `require "protected_record"`
|
|
16
|
+
* User (for now I expect a `User` class)
|
|
19
17
|
|
|
20
18
|
```ruby
|
|
21
19
|
# app/models/user.rb
|
|
22
|
-
include ProtectedRecord::
|
|
20
|
+
include ProtectedRecord::ResponsibleUser
|
|
23
21
|
# includes ProtectedRecord::ChangeRequest::Changer
|
|
24
22
|
# & ProtectedRecord::ChangeLog::Changer
|
|
25
23
|
```
|
|
24
|
+
* Your records .. these are the models you want to track
|
|
26
25
|
|
|
27
26
|
```ruby
|
|
28
|
-
# app/models/
|
|
27
|
+
# app/models/some_record.rb
|
|
29
28
|
include ProtectedRecord::Record
|
|
30
29
|
# includes ProtectedRecord::ChangeRequest::Changeling
|
|
31
30
|
# & ProtectedRecord::ChangeLog::Changeling
|
|
@@ -33,21 +32,25 @@ include ProtectedRecord::Record
|
|
|
33
32
|
|
|
34
33
|
#### Protected Keys
|
|
35
34
|
|
|
36
|
-
You have
|
|
35
|
+
You have three options,
|
|
37
36
|
|
|
38
|
-
1. Inject the `:protected_keys` option when you execute the update
|
|
39
|
-
|
|
37
|
+
1. Inject the `:protected_keys` option when you execute the update
|
|
38
|
+
(this will always take precedence over option 2).
|
|
39
|
+
2. Include in your record class `ProtectedRecord::DirtyModel`
|
|
40
|
+
and define protected_keys there
|
|
40
41
|
|
|
41
42
|
```ruby
|
|
43
|
+
# How to define :protected_keys in your models.
|
|
42
44
|
class SomeRecord < ActiveRecord::Base
|
|
43
45
|
include ProtectedRecord::DirtyModel
|
|
44
46
|
protected_keys :do_not_resuscitate, :organ_donor
|
|
45
47
|
end
|
|
46
48
|
```
|
|
47
49
|
|
|
48
|
-
|
|
50
|
+
Your third option is to omit `:protected_keys` entirely.
|
|
51
|
+
If they are not specified using either method, ProtectedRecord will use an empty array.
|
|
49
52
|
|
|
50
|
-
## Usage
|
|
53
|
+
## Usage & Function
|
|
51
54
|
|
|
52
55
|
1. protected_record will prevent changes to attributes you specify as protected.
|
|
53
56
|
2. Any attempted change will be logged as a
|
|
@@ -55,20 +58,21 @@ If you do not specify either option, ProtectedRecord will use an empty array.
|
|
|
55
58
|
3. If any changes are allowed through the filter, protected_record
|
|
56
59
|
will create a `ProtectedRecord::ChangeLog::Record` to log who changed what,
|
|
57
60
|
and for which record.
|
|
58
|
-
4. **Important
|
|
61
|
+
4. **Important!** ProtectedRecord is opt-in only. It does not change the
|
|
59
62
|
behavior of any AR methods, nor does it place any callbacks in your models.
|
|
60
63
|
In order to update with protection, use the following:
|
|
61
64
|
|
|
62
|
-
|
|
63
|
-
Rejected changes will create
|
|
64
|
-
|
|
65
|
+
In the following example, the user will be allowed to change anything
|
|
66
|
+
except `:do_not_resuscitate`. Rejected changes will create
|
|
67
|
+
`ProtectedRecord::ChangeRequest::Record` objects. Permitted changes
|
|
68
|
+
will create `ProtectedRecord::ChangeLog::Record` objects.
|
|
65
69
|
|
|
66
70
|
```ruby
|
|
67
71
|
ready = ProtectedRecord::Update.new({
|
|
68
72
|
user: current_user,
|
|
69
73
|
params: record_params,
|
|
70
74
|
protected_record: @record,
|
|
71
|
-
protected_keys: %w{ do_not_resuscitate
|
|
75
|
+
protected_keys: %w{ do_not_resuscitate }
|
|
72
76
|
})
|
|
73
77
|
|
|
74
78
|
result = ready.execute!
|
|
@@ -79,17 +83,13 @@ result.successful? #=> true
|
|
|
79
83
|
and
|
|
80
84
|
|
|
81
85
|
```ruby
|
|
82
|
-
#
|
|
86
|
+
# What changed
|
|
83
87
|
@user.change_log_records
|
|
88
|
+
@some_record.change_log_records
|
|
84
89
|
|
|
85
|
-
#
|
|
90
|
+
# What changes were attempted
|
|
86
91
|
@user.change_request_records
|
|
87
|
-
|
|
88
|
-
# What changed, and when
|
|
89
|
-
@record.change_log_records
|
|
90
|
-
|
|
91
|
-
# What changes were attempted, and when
|
|
92
|
-
@record.change_request_records
|
|
92
|
+
@some_record.change_request_records
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
## Contributing
|
data/lib/protected_record.rb
CHANGED
|
@@ -7,6 +7,6 @@ require_relative 'protected_record/use_case/change_request/create'
|
|
|
7
7
|
require_relative 'protected_record/update'
|
|
8
8
|
require_relative 'protected_record/change_log'
|
|
9
9
|
require_relative 'protected_record/change_request'
|
|
10
|
-
require_relative 'protected_record/user'
|
|
11
10
|
require_relative 'protected_record/record'
|
|
12
11
|
require_relative 'protected_record/dirty_model'
|
|
12
|
+
require_relative 'protected_record/responsible_user'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: protected_record
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tad Hosford
|
|
@@ -85,12 +85,12 @@ files:
|
|
|
85
85
|
- lib/protected_record/change_request.rb
|
|
86
86
|
- lib/protected_record/dirty_model.rb
|
|
87
87
|
- lib/protected_record/record.rb
|
|
88
|
+
- lib/protected_record/responsible_user.rb
|
|
88
89
|
- lib/protected_record/update.rb
|
|
89
90
|
- lib/protected_record/use_case/change_filter/create.rb
|
|
90
91
|
- lib/protected_record/use_case/change_log/create.rb
|
|
91
92
|
- lib/protected_record/use_case/change_request/create.rb
|
|
92
93
|
- lib/protected_record/use_case/update.rb
|
|
93
|
-
- lib/protected_record/user.rb
|
|
94
94
|
- lib/protected_record/version.rb
|
|
95
95
|
- protected_record.gemspec
|
|
96
96
|
- test/minitest_helper.rb
|