immutable_struct_ex_redactable 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a42c25462c52746ec41cd4342439fffbb683fec77c05bb5a4206e7d7b2e5476f
4
- data.tar.gz: e37bae62f51c0e8c0d8cc3acc624714f06ddbe94783509d6c0e37d84b03ca05f
3
+ metadata.gz: cfd26e195119def213e1b3b5c296761323b2e682b7afcef49cc066b9ac386a8d
4
+ data.tar.gz: e6b605a95ff4121df11a2fec4e112493610bbca5112209a5a324a18232f98549
5
5
  SHA512:
6
- metadata.gz: c3668bb96227c69b6babd198c2ee832e87e41f94a7f9c1e30f51a4606a7fbb22e1f804208f741dd5a72f7f6c7ed7291b29dea863ebfe8338ef579cb9e6f76033
7
- data.tar.gz: e0b12b781c99c6e453c4c27653fa4992181d8bfe352b14e5f4653098d2553b80910b298f47b4b04fd780995a2289861fce7b15fe9a863b027858a2693c2cd101
6
+ metadata.gz: 5032428a593c4114903acedf6cb8747b733af10874dd092d2c2c5270f8857abb069a503400f34e18bd8fe8bfba481f4e0c2c5883fb7d3afddc150f6c019c932a
7
+ data.tar.gz: 426aa1cb7650c2abd20be06a534dc9b3f543207eaae3ee3403c09a202474ed302de6ade4e376353508a9208a40fe0d346a8533232e6a42de7e298e9fc617a1d6
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
+ ## [1.2.1] - 2023-08-17
2
+
3
+ Changes
4
+
5
+ - Ruby gem updates.
6
+
7
+ ## [1.2.0] - 2022-10-03
8
+
9
+ Changes
10
+
11
+ - Add `ImmutableStructExRedactable::Configuration#redacted_unsafe` property. If this property is `true`, redacted field values will be retained and accessible as private methods on the struct named `unredacted_<field>`.
12
+ - Update README.md file.
13
+
1
14
  ## [1.1.0] - 2022-10-02
2
- * Changes
3
- * Fix rubocop violations
15
+
16
+ Changes
17
+
18
+ - Fix rubocop violations
4
19
 
5
20
  ## [1.0.0] - 2022-10-02
6
- * Initial release
21
+
22
+ Initial release
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ gemspec
7
7
 
8
8
  gem 'pry-byebug', '~> 3.9'
9
9
  gem 'rake', '~> 13.0'
10
- gem 'reek', '~> 6.1', '>= 6.1.1'
11
- gem 'rspec', '~> 3.0'
12
- gem 'rubocop', '~> 0.81.0'
13
- gem 'simplecov', '~> 0.21.2'
10
+ gem 'reek', '~> 6.1'
11
+ gem 'rspec', '~> 3.12'
12
+ gem 'rubocop', '~> 1.56.0'
13
+ gem 'simplecov', '~> 0.22.0'
data/Gemfile.lock CHANGED
@@ -1,78 +1,90 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- immutable_struct_ex_redactable (1.1.0)
5
- immutable_struct_ex (~> 0.3.0)
4
+ immutable_struct_ex_redactable (1.2.1)
5
+ immutable_struct_ex (~> 1.0, >= 1.0.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.2)
11
+ base64 (0.1.1)
11
12
  byebug (11.1.3)
12
13
  coderay (1.1.3)
13
14
  diff-lcs (1.5.0)
14
15
  docile (1.4.0)
15
- immutable_struct_ex (0.3.0)
16
- jaro_winkler (1.5.4)
16
+ immutable_struct_ex (1.0.1)
17
+ json (2.6.3)
17
18
  kwalify (0.7.2)
19
+ language_server-protocol (3.17.0.3)
18
20
  method_source (1.0.0)
19
- parallel (1.22.1)
20
- parser (3.1.2.1)
21
+ parallel (1.23.0)
22
+ parser (3.2.2.3)
21
23
  ast (~> 2.4.1)
22
- pry (0.14.1)
24
+ racc
25
+ pry (0.14.2)
23
26
  coderay (~> 1.1)
24
27
  method_source (~> 1.0)
25
28
  pry-byebug (3.10.1)
26
29
  byebug (~> 11.0)
27
30
  pry (>= 0.13, < 0.15)
31
+ racc (1.7.1)
28
32
  rainbow (3.1.1)
29
33
  rake (13.0.6)
30
- reek (6.1.1)
34
+ reek (6.1.4)
31
35
  kwalify (~> 0.7.0)
32
- parser (~> 3.1.0)
36
+ parser (~> 3.2.0)
33
37
  rainbow (>= 2.0, < 4.0)
34
- rexml (3.2.5)
35
- rspec (3.11.0)
36
- rspec-core (~> 3.11.0)
37
- rspec-expectations (~> 3.11.0)
38
- rspec-mocks (~> 3.11.0)
39
- rspec-core (3.11.0)
40
- rspec-support (~> 3.11.0)
41
- rspec-expectations (3.11.1)
38
+ regexp_parser (2.8.1)
39
+ rexml (3.2.6)
40
+ rspec (3.12.0)
41
+ rspec-core (~> 3.12.0)
42
+ rspec-expectations (~> 3.12.0)
43
+ rspec-mocks (~> 3.12.0)
44
+ rspec-core (3.12.2)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-expectations (3.12.3)
42
47
  diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.11.0)
44
- rspec-mocks (3.11.1)
48
+ rspec-support (~> 3.12.0)
49
+ rspec-mocks (3.12.6)
45
50
  diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.11.0)
47
- rspec-support (3.11.1)
48
- rubocop (0.81.0)
49
- jaro_winkler (~> 1.5.1)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-support (3.12.1)
53
+ rubocop (1.56.0)
54
+ base64 (~> 0.1.1)
55
+ json (~> 2.3)
56
+ language_server-protocol (>= 3.17.0)
50
57
  parallel (~> 1.10)
51
- parser (>= 2.7.0.1)
58
+ parser (>= 3.2.2.3)
52
59
  rainbow (>= 2.2.2, < 4.0)
53
- rexml
60
+ regexp_parser (>= 1.8, < 3.0)
61
+ rexml (>= 3.2.5, < 4.0)
62
+ rubocop-ast (>= 1.28.1, < 2.0)
54
63
  ruby-progressbar (~> 1.7)
55
- unicode-display_width (>= 1.4.0, < 2.0)
56
- ruby-progressbar (1.11.0)
57
- simplecov (0.21.2)
64
+ unicode-display_width (>= 2.4.0, < 3.0)
65
+ rubocop-ast (1.29.0)
66
+ parser (>= 3.2.1.0)
67
+ ruby-progressbar (1.13.0)
68
+ simplecov (0.22.0)
58
69
  docile (~> 1.1)
59
70
  simplecov-html (~> 0.11)
60
71
  simplecov_json_formatter (~> 0.1)
61
72
  simplecov-html (0.12.3)
62
73
  simplecov_json_formatter (0.1.4)
63
- unicode-display_width (1.8.0)
74
+ unicode-display_width (2.4.2)
64
75
 
65
76
  PLATFORMS
66
77
  x86_64-darwin-19
78
+ x86_64-linux
67
79
 
68
80
  DEPENDENCIES
69
81
  immutable_struct_ex_redactable!
70
82
  pry-byebug (~> 3.9)
71
83
  rake (~> 13.0)
72
- reek (~> 6.1, >= 6.1.1)
73
- rspec (~> 3.0)
74
- rubocop (~> 0.81.0)
75
- simplecov (~> 0.21.2)
84
+ reek (~> 6.1)
85
+ rspec (~> 3.12)
86
+ rubocop (~> 1.56.0)
87
+ simplecov (~> 0.22.0)
76
88
 
77
89
  BUNDLED WITH
78
90
  2.3.22
data/README.md CHANGED
@@ -17,14 +17,13 @@
17
17
 
18
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').
22
+
20
23
  ## Usage
21
24
 
22
25
  Follow the instructions for [Installation](#installation) first, to incorporate this gem into your code.
23
26
 
24
- ### Enhancements
25
- - Future functionality may include regex pattern for redacting field values (e.g. 'gen***@***.com').
26
- - Availability of redacted values as private fields/methods for use in `&blocks`.
27
-
28
27
  ### Basic usage
29
28
 
30
29
  #### Configure Gem Global Defaults
@@ -58,9 +57,10 @@ ImmutableStructExRedactable.create(**fields)
58
57
  => #<struct first="Jane", last="Smith", password="[REDACTED]", dob="[REDACTED]">
59
58
 
60
59
  ```
61
- NOTE: Setting the global defaults in the above manner will affect **every** *immutable_struct_ex_redactable* struct you create unless you override the global configuration options by passing a custom configuration.
62
60
 
63
- #### Overriding the Global Configuration Operions
61
+ 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.
62
+
63
+ #### Overriding the Global Configuration Options
64
64
 
65
65
  To override the global configuration options, you may do so by calling the `ImmutableStructExRedactable#create_with` method in the following manner:
66
66
 
@@ -83,6 +83,45 @@ ImmutableStructExRedactable.create_with(custom_config, **fields)
83
83
  => #<struct first="John", last="Smith", password="[NO WAY JOSE]", dob="[NO WAY JOSE]">
84
84
  ```
85
85
 
86
+ ### Access to the Original Redacted Field Values
87
+
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:
89
+
90
+ ```ruby
91
+ unredacted_<redacted field>
92
+ # Where <redacted field> == the Symbol of the redacted field.
93
+ # For example: unredacted_password, unredacted_dob, unredacted_ssn, etc.
94
+ ```
95
+
96
+ For example:
97
+
98
+ ```ruby
99
+ custom_config = ImmutableStructExRedactable::Configuration.new.tap do |config|
100
+ config.redacted_unsafe = true
101
+ end
102
+
103
+ hash = { username: 'jsmith', password: 'p@ssw0rd' }
104
+ struct = ImmutableStructExRedactable.create_with(custom_config, **hash) do
105
+ def to_h_unredacted
106
+ {
107
+ username: username,
108
+ password: send(:unredacted_password)
109
+ }
110
+ end
111
+ end
112
+ => #<struct username="jsmith", password="******">
113
+
114
+ struct.unredacted_password
115
+ #=> NoMethodError: private method `unredacted_password' called for #<struct username="jsmith", password="******">...
116
+
117
+ struct.send :unredacted_password
118
+ #=> "p@ssw0rd"
119
+
120
+ struct.to_h_unredacted
121
+ #=> {:username=>"jsmith", :password=>"p@ssw0rd"}
122
+
123
+ ```
124
+
86
125
  ### &blocks are Permitted
87
126
 
88
127
  Current `immutable_struct_ex` gem functionality is still available, so passing `&block` is permitted. See [immutable_struct_ex](https://rubygems.org/gems/immutable_struct_ex) gem for more details:
@@ -38,17 +38,33 @@ module ImmutableStructExRedactable
38
38
  # @return [String] the label that should replace redacted field values.
39
39
  attr_accessor :redacted_label
40
40
 
41
+ # Gets/sets the redacted unsafe switch that determines whether or not
42
+ # redacted field values are retained as private methods named
43
+ # #unredacted_<field> on the struct returned. If this configuration
44
+ # property is true, redacted field values will be retained and
45
+ # accessible as private methods on the struct.
46
+ #
47
+ # The default is false.
48
+ #
49
+ # @return [Bool] the unsafe switch value.
50
+ attr_accessor :redacted_unsafe
51
+
41
52
  # The constructor; calls {#reset}.
42
53
  def initialize
43
54
  reset
44
55
  end
45
56
 
57
+ def redacted_unsafe?
58
+ @redacted_unsafe
59
+ end
60
+
46
61
  # Resets the configuration settings to their default values.
47
62
  #
48
63
  # @return [void]
49
64
  def reset
50
65
  @redacted = %i[password]
51
66
  @redacted_label = '******'
67
+ @redacted_unsafe = false
52
68
  end
53
69
  end
54
70
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImmutableStructExRedactable
4
+ module RedactedAccessible
5
+ class << self
6
+ def included(base)
7
+ base.extend ClassModules
8
+ end
9
+ end
10
+
11
+ module ClassModules
12
+ def redacted_accessible_module_for(hash:, config:)
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
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ImmutableStructExRedactable
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.1'
5
5
  end
@@ -2,9 +2,12 @@
2
2
 
3
3
  require 'immutable_struct_ex'
4
4
  require_relative 'immutable_struct_ex_redactable/configuration'
5
+ require_relative 'immutable_struct_ex_redactable/redacted_accessible'
5
6
  require_relative 'immutable_struct_ex_redactable/version'
6
7
 
7
8
  module ImmutableStructExRedactable
9
+ include RedactedAccessible
10
+
8
11
  module_function
9
12
 
10
13
  def create(**hash, &block)
@@ -13,12 +16,19 @@ module ImmutableStructExRedactable
13
16
  end
14
17
 
15
18
  def create_with(config, **hash, &block)
19
+ if config.redacted_unsafe?
20
+ redacted_private_accessible_module =
21
+ redacted_accessible_module_for(hash: hash, config: config)
22
+ end
23
+
16
24
  config.redacted.each do |attr|
17
25
  next unless hash.key? attr
18
26
 
19
27
  hash[attr] = config.redacted_label
20
28
  end
21
29
 
22
- ImmutableStructEx.new(**hash, &block)
30
+ ImmutableStructEx.new(**hash, &block).tap do |struct|
31
+ struct.extend(redacted_private_accessible_module) if config.redacted_unsafe?
32
+ end
23
33
  end
24
34
  end
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.1.0
4
+ version: 1.2.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: 2022-10-02 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: immutable_struct_ex
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: 0.3.0
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.1
27
33
  description: Creates and initializes an immutable struct in one step and provides
28
34
  redaction functionality.
29
35
  email:
@@ -44,9 +50,9 @@ files:
44
50
  - Rakefile
45
51
  - bin/console
46
52
  - bin/setup
47
- - immutable_struct_ex_redactable.gemspec
48
53
  - lib/immutable_struct_ex_redactable.rb
49
54
  - lib/immutable_struct_ex_redactable/configuration.rb
55
+ - lib/immutable_struct_ex_redactable/redacted_accessible.rb
50
56
  - lib/immutable_struct_ex_redactable/version.rb
51
57
  - sig/immutable_struct_ex_redactable.rbs
52
58
  homepage: https://github.com/gangelo/immutable_struct_ex_redactable
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/immutable_struct_ex_redactable/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'immutable_struct_ex_redactable'
7
- spec.version = ImmutableStructExRedactable::VERSION
8
- spec.authors = ['Gene M. Angelo, Jr.']
9
- spec.email = ['public.gma@gmail.com']
10
-
11
- spec.summary = 'The redactable version of the immutable_stuct_ex gem.'
12
- spec.description = 'Creates and initializes an immutable struct in one step and provides redaction functionality.'
13
- spec.homepage = 'https://github.com/gangelo/immutable_struct_ex_redactable'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 3.0.1'
16
-
17
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
-
19
- spec.metadata['homepage_uri'] = spec.homepage
20
- spec.metadata['source_code_uri'] = spec.homepage
21
- spec.metadata['changelog_uri'] = 'https://github.com/gangelo/immutable_struct_ex_redactable/blob/main/CHANGELOG.md'
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
- end
29
- end
30
- spec.bindir = 'exe'
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ['lib']
33
-
34
- # Uncomment to register a new dependency of your gem
35
- spec.add_dependency 'immutable_struct_ex', '~> 0.3.0'
36
- spec.metadata['rubygems_mfa_required'] = 'true'
37
- end