protected_record 0.0.2 → 0.0.3

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: 9b986b59a39e95c1cf010e1d832fe5e3b113a09b
4
- data.tar.gz: 9aaf2d518fb70dc521b35fee444af5b745448ab7
3
+ metadata.gz: 3ba5e182fe0caec23566af06a804659fd64927ce
4
+ data.tar.gz: dd283cab9d1fef2b38b4468acc7c57f332b4af76
5
5
  SHA512:
6
- metadata.gz: e56a6564bf7007ab129daba444ff2d3e05416e0e0430203de47a6eee348ee42714bb3e0b939aaba998fef5ff48ffb9991f11d4d35e6be1709d50661440afd073
7
- data.tar.gz: cc0a5f9563e9bb726611c8935d967f182136881060f28bd22604818c0150afde4eb9b828acbeecf86bbee452af3a6a4cec264a233d6b3836001e0f81713f90b3
6
+ metadata.gz: 0c8a5c244a1ca72eb8a70e9c4afe89664ff1307e5db0832192fd39faea382efd305bb6ce8d08d81bd00fd5273dbe4732d9942c12d37c7041aa9035c678c5dcb2
7
+ data.tar.gz: a609d10024a34d026e45203bf85179d2b188e4d3ddeb9a8595eea7dc6f0532f8cfb2db972f37eab1c3e4643e7c1a65db2da41f255e244e190e4b711dba91ea19
data/README.md CHANGED
@@ -1,47 +1,67 @@
1
1
  # protected_record
2
- ## Description
3
- protected_record will prevent changes to attributes you specify as protected. Any attempted change will be logged as a ProtectedRecord::ChangeRequest::Record.
4
- If any changes are allowed through the filter, protected_record will create a ProtectedRecord::ChangeLog::Record to log who changed what, and for which record.
5
- ProtectedRecord is opt-in only. In order to update with protection, use the following:
2
+ ## Setup for rails applications
3
+ I've created an engine to provide the necessary migrations as well as a basic interface for traiging change requests. You are free to use this gem without the engine, but you'll need to visit [protected_record_manager](https://github.com/rthbound/protected_record_manager/tree/master/db/migrate) and copy the migrations into your app manually.
6
4
 
7
- result = ProtectedRecord::UseCase::Update.new({
8
- params: visit_params,
9
- protected_record: @patient_visit,
10
- user: current_user,
11
- protected_keys: %w{ visit_date do_not_resuscitate }
12
- }).execute!
5
+ Add to your Rails application's Gemfile:
13
6
 
7
+ gem "protected_record_manager"
8
+
9
+ And to your Rails application's `routes.rb`:
10
+ ```ruby
11
+ mount ProtectedRecordManager::Engine, :at => "/protected_record_manager", as: "protected_record_manager"
12
+ ```
13
+ Which will provide a user interface for triaging change requests at:
14
+ ```
15
+ http://localhost:3000/protected_record_manager/change_requests
16
+ ```
17
+ **Important:** Only users with `@user.protected_record_manager == true` will be able to access these resources.
14
18
 
15
- ## Usage
16
-
17
- To get started, just include in your tracked models:
18
-
19
- include ProtectedRecord::ChangeRequest::Changeling
20
- include ProtectedRecord::ChangeLog::Changeling
21
-
22
- and include in your user model:
19
+ Now copy over and run the migrations:
20
+ ```
21
+ $ rake protected_record_manager:install:migrations
22
+ $ rake db:migrate
23
+ ```
24
+ Lastly, you'll need to prepare your models. There's two types of models at play here:
23
25
 
24
- include ProtectedRecord::ChangeRequest::Changer
25
- include ProtectedRecord::ChangeLog::Changer
26
+ 1. User (for now I expect a `User` class and `current_user` method
27
+ 2. records .. these are the models you want to track
26
28
 
27
- then in your controller
29
+ So in `user.rb`
30
+ ```ruby
31
+ include ProtectedRecord::ChangeRequest::Changer
32
+ include ProtectedRecord::ChangeLog::Changer
33
+ ```
28
34
 
29
- # UseCase module will filter changes to protected_keys,
30
- # creating a "change request" rather than applying changes
31
-
32
- # UseCase module will allow other changes to be applied,
33
- # creating a "change log" entry for the observed changes
35
+ And in any model where you want to use protection:
36
+ ```ruby
37
+ include ProtectedRecord::ChangeRequest::Changeling
38
+ include ProtectedRecord::ChangeLog::Changeling
39
+ ```
40
+ ## Usage
41
+ 1. protected_record will prevent changes to attributes you specify as protected.
42
+ 2. Any attempted change will be logged as a `ProtectedRecord::ChangeRequest::Record`.
43
+ 3. If any changes are allowed through the filter, protected_record will create a `ProtectedRecord::ChangeLog::Record` to log who changed what, and for which record.
44
+ 4. **Important**: ProtectedRecord is opt-in only. It does not change the way behavior of any AR methods, nor does it use any callbacks. In order to update with protection, use the following:
34
45
 
35
- update_result = ProtectedRecord::UseCase::Update.new({
36
- params: visit_params,
37
- protected_record: @patient_visit,
38
- user: current_user,
39
- protected_keys: %w{ visit_date do_not_resuscitate }
40
- }).execute!
46
+ ```ruby
47
+ result = ProtectedRecord::UseCase::Update.new({
48
+ params: record_params,
49
+ protected_record: @record,
50
+ user: current_user,
51
+ protected_keys: %w{ do_not_resuscitate organ_donor }
52
+ }).execute!
41
53
 
42
- update_result.successful?
54
+ # UseCase module will filter changes to protected_keys,
55
+ # creating a "change request" rather than applying changes
43
56
 
57
+ # UseCase module will allow other changes to be applied,
58
+ # creating a "change log" entry for the observed changes
59
+ update_result.successful? #=> true
60
+ ```
44
61
  and call methods like
45
-
46
- @user.change_log_records
47
- @user.change_request_records
62
+ ```ruby
63
+ @user.change_log_records
64
+ @user.change_request_records
65
+ @record.change_log_records
66
+ @record.change_request_records
67
+ ```
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  module ProtectedRecord
3
2
  module UseCase
4
3
  module ChangeRequest
@@ -1,3 +1,3 @@
1
1
  module ProtectedRecord
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require "minitest_helper"
2
2
  require "active_record"
3
- require "pry"
4
3
 
5
4
  describe ProtectedRecord::UseCase::ChangeFilter::Create do
6
5
  describe "new" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protected_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tad Hosford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-23 00:00:00.000000000 Z
11
+ date: 2013-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pay_dirt