immutable_struct_ex_redactable 1.2.2 → 1.3.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
  SHA256:
3
- metadata.gz: 0f17e2eaa97e190007e9d795ffd67d994b95fad1f31e6ba1cac068bed1f1738a
4
- data.tar.gz: 395fddfefe67e8271bf01fd7440c322d92055b97b234de76c3e4242f40c5bb18
3
+ metadata.gz: 0c4f3f6ce9e3f02ca66a1b18ab28082daa4f6a34982a4e5c2eb77353a3b6f20f
4
+ data.tar.gz: 0df6795630105361be3ff215e358b84574bee88b969ecdbe325ea3423aeea22e
5
5
  SHA512:
6
- metadata.gz: 4a246e5fb6044949e70b56371faed89913d574588e21a989178e51b388609fe85af9bc0c8c9634afa3d6dff5bc0fe94f9288c769fcea708cd790ae4ab6623811
7
- data.tar.gz: 7882512c517e1d1c6ec649cda8654687675c042a96f7e1976e2dd112b1d67dcdcb23cdb70540197367b03b5a689b998325959b2e99ec22e4dcac637f44890613
6
+ metadata.gz: 0d5e62274412520398f484e497104d413dc93ad407a9511295abd47978c92e6e189d82d6850e53eefc378e3a93532fc27b02c26f0bb41ac0ad7cde01a9677327
7
+ data.tar.gz: 97d9bf80cf892b847e5eac46893abe160c0d4f16e3cbe5775fc4fd959ebaee5e1b08706812a90da3dbbf4cd16fcf8e327673898f3573440bd611ea74121e1411
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [1.3.1] - 2023-11-01
2
+
3
+ Changes
4
+
5
+ - Ruby gem updates.
6
+
7
+ ## [1.3.0] - 2023-09-03
8
+
9
+ Changes
10
+
11
+ - `ImmutableStructExRedactable::Configuration#whitelist` is now supported. Attributes added to #whitelist will not be redacted. All other attributes will be redacted.
12
+ - `ImmutableStructExRedactable::Configuration#redacted` will be deprecated in a future release. Please use `ImmutableStructExRedactable::Configuration#blacklist` instead.
13
+
1
14
  ## [1.2.2] - 2023-08-29
2
15
 
3
16
  Changes
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- immutable_struct_ex_redactable (1.2.2)
4
+ immutable_struct_ex_redactable (1.3.1)
5
5
  immutable_struct_ex (~> 1.0, >= 1.0.1)
6
6
 
7
7
  GEM
@@ -13,13 +13,13 @@ GEM
13
13
  coderay (1.1.3)
14
14
  diff-lcs (1.5.0)
15
15
  docile (1.4.0)
16
- immutable_struct_ex (1.0.1)
16
+ immutable_struct_ex (1.0.3)
17
17
  json (2.6.3)
18
18
  kwalify (0.7.2)
19
19
  language_server-protocol (3.17.0.3)
20
20
  method_source (1.0.0)
21
21
  parallel (1.23.0)
22
- parser (3.2.2.3)
22
+ parser (3.2.2.4)
23
23
  ast (~> 2.4.1)
24
24
  racc
25
25
  pry (0.14.2)
@@ -28,14 +28,14 @@ GEM
28
28
  pry-byebug (3.10.1)
29
29
  byebug (~> 11.0)
30
30
  pry (>= 0.13, < 0.15)
31
- racc (1.7.1)
31
+ racc (1.7.2)
32
32
  rainbow (3.1.1)
33
- rake (13.0.6)
33
+ rake (13.1.0)
34
34
  reek (6.1.4)
35
35
  kwalify (~> 0.7.0)
36
36
  parser (~> 3.2.0)
37
37
  rainbow (>= 2.0, < 4.0)
38
- regexp_parser (2.8.1)
38
+ regexp_parser (2.8.2)
39
39
  rexml (3.2.6)
40
40
  rspec (3.12.0)
41
41
  rspec-core (~> 3.12.0)
@@ -50,7 +50,7 @@ GEM
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.12.0)
52
52
  rspec-support (3.12.1)
53
- rubocop (1.56.2)
53
+ rubocop (1.56.4)
54
54
  base64 (~> 0.1.1)
55
55
  json (~> 2.3)
56
56
  language_server-protocol (>= 3.17.0)
@@ -62,7 +62,7 @@ GEM
62
62
  rubocop-ast (>= 1.28.1, < 2.0)
63
63
  ruby-progressbar (~> 1.7)
64
64
  unicode-display_width (>= 2.4.0, < 3.0)
65
- rubocop-ast (1.29.0)
65
+ rubocop-ast (1.30.0)
66
66
  parser (>= 3.2.1.0)
67
67
  ruby-progressbar (1.13.0)
68
68
  simplecov (0.22.0)
@@ -71,7 +71,7 @@ GEM
71
71
  simplecov_json_formatter (~> 0.1)
72
72
  simplecov-html (0.12.3)
73
73
  simplecov_json_formatter (0.1.4)
74
- unicode-display_width (2.4.2)
74
+ unicode-display_width (2.5.0)
75
75
 
76
76
  PLATFORMS
77
77
  x86_64-darwin-19
data/README.md CHANGED
@@ -15,10 +15,9 @@
15
15
 
16
16
  `immutable_struct_ex_redactable` is the *redactable version* of the world-famous *immutable_struct_ex* immutable struct :). To find out more about the *immutable_struct_ex* gem, visit the Rubygems.org entry for [immutable_struct_ex](https://rubygems.org/gems/immutable_struct_ex).
17
17
 
18
- `immutable_struct_ex_redactable` maintains all the functionality of the *immutable_struct_ex* gem, but allows you to create immutable structs that can be configured to redact field values using standard gem configuration (`ImmutableStructExRedactable.configure { |config| ... }`) or by passing configuration options to the appropriate method (`ImmutableStructExRedactable.create_with(config, ...)`)
18
+ `immutable_struct_ex_redactable` maintains all the functionality of the *immutable_struct_ex* gem, but allows you to create immutable structs that can be configured to redact field values using standard gem configuration (`ImmutableStructExRedactable.configure { |config| ... }`) or by passing configuration options to the appropriate method (`ImmutableStructExRedactable.create_with(config, ...)`).
19
19
 
20
- ### Future Enhancements
21
- - Future functionality will probably accept regex pattern for redacting field values (e.g. 'gen***@***.com').
20
+ NOTE: both **whitelisting** and **blacklisting** are supported.
22
21
 
23
22
  ## Usage
24
23
 
@@ -28,11 +27,12 @@ Follow the instructions for [Installation](#installation) first, to incorporate
28
27
 
29
28
  #### Configure Gem Global Defaults
30
29
 
31
- *immutable_struct_ex_redactable*, by default, will redact fields named `:password` using the redacted label `"******"`. This will not meet your needs in all circumstances most likely. If this is *not* the case, you may change the default redactable fields and redactable label by changing the *immutable_struct_ex_redactable* configuration as follows:
30
+ *immutable_struct_ex_redactable*, by default, will redact fields named `:password` using the redacted label `"******"`. This will not meet your needs in all circumstances most likely. If this is *not* the case, you may change the fields that are redacted and the redactable label by changing the *immutable_struct_ex_redactable* configuration via the `#whitelist` or `#blacklist` configuration options:
32
31
 
32
+ ##### Using a whitelist
33
33
  ```ruby
34
34
  ImmutableStructExRedactable::configure do |config|
35
- config.redacted = %i[password dob ssn phone]
35
+ config.whitelist = %i[first last]
36
36
  config.redacted_label = '[REDACTED]'
37
37
  end
38
38
 
@@ -55,7 +55,34 @@ fields = {
55
55
 
56
56
  ImmutableStructExRedactable.create(**fields)
57
57
  => #<struct first="Jane", last="Smith", password="[REDACTED]", dob="[REDACTED]">
58
+ ```
59
+
60
+ ##### Using a blacklist
61
+ ```ruby
62
+ ImmutableStructExRedactable::configure do |config|
63
+ config.blacklist = %i[password dob ssn phone]
64
+ config.redacted_label = '[REDACTED]'
65
+ end
66
+
67
+ fields = {
68
+ first: 'John',
69
+ last: 'Smith',
70
+ password: 'p@ssw0rd',
71
+ dob: '1986-05-12'
72
+ }
58
73
 
74
+ ImmutableStructExRedactable.create(**fields)
75
+ => #<struct first="John", last="Smith", password="[REDACTED]", dob="[REDACTED]">
76
+
77
+ fields = {
78
+ first: 'Jane',
79
+ last: 'Smith',
80
+ password: 'h3l10W04lD',
81
+ dob: '1990-12-26'
82
+ }
83
+
84
+ ImmutableStructExRedactable.create(**fields)
85
+ => #<struct first="Jane", last="Smith", password="[REDACTED]", dob="[REDACTED]">
59
86
  ```
60
87
 
61
88
  NOTE: Setting the global defaults in the above manner will affect **every** *immutable_struct_ex_redactable* struct instance you create unless you override the global configuration options, by passing a custom configuration.
@@ -67,7 +94,7 @@ To override the global configuration options, you may do so by calling the `Immu
67
94
  ```ruby
68
95
  # Create a custom configuration with the options you want to use.
69
96
  custom_config = ImmutableStructExRedactable::Configuration.new.tap do |config|
70
- config.redacted = %i[password dob]
97
+ config.whitelist = %i[first last]
71
98
  config.redacted_label = '[NO WAY JOSE]'
72
99
  end
73
100
 
@@ -85,7 +112,7 @@ ImmutableStructExRedactable.create_with(custom_config, **fields)
85
112
 
86
113
  ### Access to the Original Redacted Field Values
87
114
 
88
- By default, *immutable_struct_ex_redactable* **will not** allow access to redacted field values; that is, field values marked for redaction via the global configuration (`ImmutableStructExRedactable::Configuration#redacted`) or by overriding the global configuration by passing a custom configuration (`ImmutableStructExRedactable.create_with(my_config, ...)`). However, if you really *need* access to redacted field values in their original, *un*redacted form, you can turn on the `ImmutableStructExRedactable::Configuration#redacted_unsafe` option in the global configuration or turn this same option on when passing a custom configuration. Turning the `redacted_unsafe` configuration option on in either scenario will instruct *immutable_struct_ex_redactable* to create *private methods* on structs created that will allow access to the original *un*redacted field values via `send:`. The *private methods* created that will allow access to the original *un*redacted field values, will have the following naming convention:
115
+ By default, *immutable_struct_ex_redactable* **will not** allow access to redacted field values; that is, field values marked for redaction via the global configuration (`ImmutableStructExRedactable::Configuration#whitelist/#blacklist`) or by overriding the global configuration by passing a custom configuration (`ImmutableStructExRedactable.create_with(my_config, ...)`). However, if you really *need* access to redacted field values in their original, *un*redacted form, you can turn on the `ImmutableStructExRedactable::Configuration#redacted_unsafe` option in the global configuration or turn this same option on when passing a custom configuration. Turning the `redacted_unsafe` configuration option on in either scenario will instruct *immutable_struct_ex_redactable* to create *private methods* on structs created that will allow access to the original *un*redacted field values via `send:`. The *private methods* created that will allow access to the original *un*redacted field values, will have the following naming convention:
89
116
 
90
117
  ```ruby
91
118
  unredacted_<redacted field>
@@ -97,6 +124,7 @@ For example:
97
124
 
98
125
  ```ruby
99
126
  custom_config = ImmutableStructExRedactable::Configuration.new.tap do |config|
127
+ config.whitelist = %i[username]
100
128
  config.redacted_unsafe = true
101
129
  end
102
130
 
@@ -119,7 +147,6 @@ struct.send :unredacted_password
119
147
 
120
148
  struct.to_h_unredacted
121
149
  #=> {:username=>"jsmith", :password=>"p@ssw0rd"}
122
-
123
150
  ```
124
151
 
125
152
  ### &blocks are Permitted
@@ -165,7 +192,7 @@ class MyRedactableImmutableStruct
165
192
 
166
193
  def config
167
194
  @config ||= ImmutableStructExRedactable::Configuration.new.tap do |config|
168
- config.redacted = %i[password]
195
+ config.whitelist = %i[username]
169
196
  config.redacted_label = 'xxxxxx'
170
197
  end
171
198
  end
data/bin/console CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  require 'bundler/setup'
5
5
  require 'immutable_struct_ex_redactable'
6
- require 'immutable_struct_ex_redactable/configuration'
7
6
 
8
7
  require 'pry-byebug'
9
8
  Pry.start
@@ -24,12 +24,21 @@ module ImmutableStructExRedactable
24
24
  # This class encapsulates the configuration properties for this gem and
25
25
  # provides methods and attributes that allow for management of the same.
26
26
  class Configuration
27
- # Gets/sets the fields that should be redacted for this gem.
27
+ # Gets/sets the blacklisted fields that should be redacted for this gem.
28
28
  #
29
29
  # The default is %i[password].
30
30
  #
31
31
  # @return [Array<Symbol>] an Array of Symbols that should be redacted.
32
- attr_accessor :redacted
32
+ attr_accessor :blacklist
33
+ alias redacted blacklist
34
+ alias redacted= blacklist=
35
+
36
+ # Gets/sets the whitelisted fields that should not be redacted for this gem.
37
+ #
38
+ # The default is [].
39
+ #
40
+ # @return [Array<Symbol>] an Array of Symbols that should be whitelisted.
41
+ attr_accessor :whitelist
33
42
 
34
43
  # Gets/sets the label that should replace redacted field values.
35
44
  #
@@ -62,7 +71,8 @@ module ImmutableStructExRedactable
62
71
  #
63
72
  # @return [void]
64
73
  def reset
65
- @redacted = %i[password]
74
+ @blacklist = %i[password]
75
+ @whitelist = []
66
76
  @redacted_label = '******'
67
77
  @redacted_unsafe = false
68
78
  end
@@ -11,15 +11,30 @@ module ImmutableStructExRedactable
11
11
  module ClassModules
12
12
  def redacted_accessible_module_for(hash:, config:)
13
13
  Module.new do
14
- config.redacted.each do |attr|
15
- unredacted_attr_method = "unredacted_#{attr}"
16
- code = <<~CODE
17
- def #{unredacted_attr_method}
18
- "#{hash[attr]}"
19
- end
20
- private :#{unredacted_attr_method}
21
- CODE
22
- class_eval code
14
+ if config.whitelist.any?
15
+ hash.each do |attr, _|
16
+ next if config.whitelist.include? attr
17
+
18
+ unredacted_attr_method = "unredacted_#{attr}"
19
+ code = <<~CODE
20
+ def #{unredacted_attr_method}
21
+ "#{hash[attr]}"
22
+ end
23
+ private :#{unredacted_attr_method}
24
+ CODE
25
+ class_eval code
26
+ end
27
+ else
28
+ config.blacklist.each do |attr|
29
+ unredacted_attr_method = "unredacted_#{attr}"
30
+ code = <<~CODE
31
+ def #{unredacted_attr_method}
32
+ "#{hash[attr]}"
33
+ end
34
+ private :#{unredacted_attr_method}
35
+ CODE
36
+ class_eval code
37
+ end
23
38
  end
24
39
  end
25
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImmutableStructExRedactable
4
- VERSION = '1.2.2'
4
+ VERSION = '1.3.1'
5
5
  end
@@ -21,10 +21,18 @@ module ImmutableStructExRedactable
21
21
  redacted_accessible_module_for(hash: hash, config: config)
22
22
  end
23
23
 
24
- config.redacted.each do |attr|
25
- next unless hash.key? attr
26
-
27
- hash[attr] = config.redacted_label
24
+ if config.whitelist.any?
25
+ hash.each do |key, _|
26
+ next if config.whitelist.include? key
27
+
28
+ hash[key] = config.redacted_label
29
+ end
30
+ else
31
+ config.blacklist.each do |attr|
32
+ next unless hash.key? attr
33
+
34
+ hash[attr] = config.redacted_label
35
+ end
28
36
  end
29
37
 
30
38
  ImmutableStructEx.new(**hash, &block).tap do |struct|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immutable_struct_ex_redactable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene M. Angelo, Jr.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-29 00:00:00.000000000 Z
11
+ date: 2023-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: immutable_struct_ex
@@ -63,7 +63,14 @@ metadata:
63
63
  source_code_uri: https://github.com/gangelo/immutable_struct_ex_redactable
64
64
  changelog_uri: https://github.com/gangelo/immutable_struct_ex_redactable/blob/main/CHANGELOG.md
65
65
  rubygems_mfa_required: 'true'
66
- post_install_message:
66
+ post_install_message: |
67
+ Thank you for installing immutable_struct_ex_redactable.
68
+
69
+ immutable_struct_ex_redactable now supports `ImmutableStructExRedactable::Configuration#whitelist`
70
+ See the README.md for more information.
71
+
72
+ Please note that `ImmutableStructExRedactable::Configuration#redacted` will be deprecated in a future release.
73
+ Please use `ImmutableStructExRedactable::Configuration#blacklist` instead.
67
74
  rdoc_options: []
68
75
  require_paths:
69
76
  - lib