protected_record 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b07d6ebf3ed0d4992e9ee6918d5abbea15ce1a2
4
- data.tar.gz: 20bac695f688e80e68e0a286d687a51b97411ff3
3
+ metadata.gz: ee3db2399060139dabe4efb989ce1b857ee1e018
4
+ data.tar.gz: 34ff5f83cd940b7535ee3a28336295de5a4add6b
5
5
  SHA512:
6
- metadata.gz: d42e0214fbf3dab9fc948bb4f6b2e742f2d6aaa98a9862ed33fba9b91e370038b4891779b57d84e2a68c4732e894a1a57c2dbaa7843caf5b320761452f4c00ab
7
- data.tar.gz: 0d8fdbc2ad2c3b613c809a99956844ec7c460bd4e2086a64f99ab7ab581e1fa4e549882c91b4cc707ab5f22aea4884c6f242758a486263e9a86df89123e9ccdc
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 an engine to provide the necessary migrations as well as a (very)
6
- basic interface for triaging `ProtectedRecord::ChangeRequest::Record` objects.
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
- 1. User (for now I expect a `User` class and `current_user` method
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::User
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/any.rb
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 two options,
35
+ You have three options,
37
36
 
38
- 1. Inject the `:protected_keys` option when you execute the update (this will always take precedence)
39
- 2. Include in your record class `ProtectedRecord::DirtyModel` and define them there:
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
- If you do not specify either option, ProtectedRecord will use an empty array.
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**: ProtectedRecord is opt-in only. It does not change the
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
- This user can change anything but `:do_not_resuscitate`and `:organ_donor`.
63
- Rejected changes will create `ProtectedRecord::ChangeRequest::Record` objects.
64
- Permitted changes will create `ProtectedRecord::ChangeLog::Record` objects.
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 organ_donor }
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
- # Who changed what, and when
86
+ # What changed
83
87
  @user.change_log_records
88
+ @some_record.change_log_records
84
89
 
85
- # Who attempted to change what, and when
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
@@ -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'
@@ -1,5 +1,5 @@
1
1
  module ProtectedRecord
2
- module User
2
+ module ResponsibleUser
3
3
  def self.included(base)
4
4
  base.send :include, ProtectedRecord::ChangeLog::Changer
5
5
  base.send :include, ProtectedRecord::ChangeRequest::Changer
@@ -1,3 +1,3 @@
1
1
  module ProtectedRecord
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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