attr_redactor 0.2.0 → 0.3.0

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: 5caa6c4d80818958922fcd7501a7b88e6b9eedbb
4
- data.tar.gz: 29e9e0d0b15a9af7c6fd728619044e964f94561c
3
+ metadata.gz: f8f5402fd6e0a62adeed50b6326b8c5a890cfee8
4
+ data.tar.gz: e2023832b6878e36199642220921e6270107e056
5
5
  SHA512:
6
- metadata.gz: 587a18cef3b3428d2bc81c29a0d64b90da8564794c59112e4453c4304cba7d8e16d62d207116aa9456add2a469c72f02ccc18b8fc85f8d85ac63e1af34e30093
7
- data.tar.gz: 1adbc5fa1f91a4fe848863f3f5894bc9ee8fe4f703aec7ed245a08eb03b4805fd08c08ab0d83ddc509c3e1118ff1077b43cbc334e683a2bf2a94c40307f113fd
6
+ metadata.gz: a48ee64c229713ef201046b9d50ee1b2e6e7caa0508acfb1a37810dd230423758d6b5c5751d956a183d90bef70e8c74ee8295817df9fe8cfcbe52fd7fbb6f367
7
+ data.tar.gz: b4e5f13e0925b34f1a4dfef7a32b0eee28eebdefa6771efcacb41a8233e858d4ede3143c799555677479be0d67fcf60bdfff98c94631405e9934e2b77a0663ba
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # attr_redactor #
2
2
 
3
+ ##0.3.0 ##
4
+ * Changed: Version bump hash_redactor for string values for redact (@chrisjensen)
5
+
6
+ ##0.2.1 ##
7
+ * Added: Explicit tests and documentation for using proc/lambda/method for redact (@chrisjensen)
8
+
3
9
  ##0.2.0 ##
4
10
  * Fixed: Updated hash_redactor dependency for failure on encrypting nil (@chrisjensen)
5
11
 
data/README.md CHANGED
@@ -90,6 +90,25 @@ To ensure ActiveRecord saves changed data, you should always update the hash ent
90
90
  user.user_data[:email] # 'personal@email.com'
91
91
  ```
92
92
 
93
+ ### Using a dynamic redact hash
94
+ The value of redact can be a symbol, lambda or proc. If it's a symbol, that method will be called on the object itself. This allows you to create custom redact hashes on a per record basis.
95
+
96
+ ```
97
+ class User < ActiveRecord::Base
98
+ belongs_to :company
99
+ attr_redactor :user_data, :redact => :redact_hash
100
+
101
+ def redact_hash
102
+ company.redact_settings
103
+ end
104
+ end
105
+
106
+ user = User.new user_data: { ssn: '123-45-6789', email: 'personal@email.com' }
107
+
108
+ # What get's redacted in user_data depends on the company settings for that user
109
+ ```
110
+
111
+
93
112
  ### attr_redacted with database persistence
94
113
 
95
114
  By default, `attr_redacted` stores the redacted data in `:redacted_<attribute>`.
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.required_ruby_version = '>= 2.0.0'
30
30
 
31
- s.add_dependency('hash_redactor', ['~> 0.3.1'])
31
+ s.add_dependency('hash_redactor', ['~> 0.4.0'])
32
32
  # support for testing with specific active record version
33
33
  activerecord_version = if ENV.key?('ACTIVERECORD')
34
34
  "~> #{ENV['ACTIVERECORD']}"
@@ -2,7 +2,7 @@ module AttrRedactor
2
2
  # Contains information about this gem's version
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 2
5
+ MINOR = 3
6
6
  PATCH = 0
7
7
 
8
8
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
@@ -63,6 +63,16 @@ class AlternativeClass
63
63
  attr_redactor :secret
64
64
  end
65
65
 
66
+ class Post
67
+ extend AttrRedactor
68
+
69
+ attr_redactor :post_info, :redact => :redact_hash,
70
+ encryption_key: 'encryption_key is super long and unguessable',
71
+ digest_salt: 'pink himalayan'
72
+
73
+ attr_accessor :redact_hash
74
+ end
75
+
66
76
  class SubClass < AlternativeClass
67
77
  attr_redactor :testing
68
78
  end
@@ -80,8 +90,6 @@ class AttrRedactorTest < Minitest::Test
80
90
  @iv = SecureRandom.random_bytes(12)
81
91
  end
82
92
 
83
- i_suck_and_my_tests_are_order_dependent!
84
-
85
93
  def data_to_redact
86
94
  {
87
95
  :ssn => 'my secret ssn',
@@ -275,4 +283,37 @@ class AttrRedactorTest < Minitest::Test
275
283
  @user.data = data_to_redact
276
284
  assert_equal unredacted_data, @user.data
277
285
  end
286
+
287
+ def test_redact_hash_from_function
288
+ post_data = { :followers => 'macy, george', :critics => 'Barbados Glum',
289
+ :bio => 'A strange, quiet man' }
290
+
291
+ redact_hash1 = {
292
+ :followers => :remove,
293
+ :critics => :encrypt,
294
+ :bio => :digest
295
+ }
296
+
297
+ redact_hash2 = {
298
+ :followers => :keep,
299
+ :critics => :digest,
300
+ :bio => :encrypt
301
+ }
302
+
303
+ post = Post.new
304
+ post.redact_hash = redact_hash1
305
+ post.post_info = post_data
306
+
307
+ post2 = Post.new
308
+ post2.redact_hash = redact_hash2
309
+ post2.post_info = post_data
310
+
311
+ refute post.redacted_post_info.has_key? :followers
312
+ assert post.redacted_post_info.has_key? :encrypted_critics
313
+ assert post.redacted_post_info.has_key? :bio_digest
314
+
315
+ assert post2.redacted_post_info.has_key? :followers
316
+ assert post2.redacted_post_info.has_key? :critics_digest
317
+ assert post2.redacted_post_info.has_key? :encrypted_bio
318
+ end
278
319
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_redactor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2016-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hash_redactor
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.1
19
+ version: 0.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.1
26
+ version: 0.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement