immutable_struct_ex_redactable 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 163f8c7094c8255005b9ff1912d6993707e756024f652c2c78a29fec22a2d6cb
4
+ data.tar.gz: 05dbd70e92271dfe52a049a404c0c15afb962b584fd18d4c9b7a2823c03d7ce6
5
+ SHA512:
6
+ metadata.gz: 443ce94ada0122523164187c162a422816c5142455eecbe0831ef3b196fbf3d4c7919679b2dd8ebcee402a4099ada92c04feda2653c3d49b835390b6474aec07
7
+ data.tar.gz: 6ef92da7762b45fb9f99097a46d42de9ccf70c58868950e333a11526577251d1142993162c614d18a7d8a05b237d16cb7b8b17a1836418aa760da41a86ea3cec
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,186 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.0
7
+ NewCops: enable
8
+ Exclude:
9
+ - '.git/**/*'
10
+ - '.idea/**/*'
11
+ - 'init/*'
12
+ - 'Rakefile'
13
+ - 'vendor/**/*'
14
+ - 'scratch*.rb'
15
+
16
+ # Align the elements of a hash literal if they span more than one line.
17
+ Layout/HashAlignment:
18
+ EnforcedLastArgumentHashStyle: always_ignore
19
+
20
+ # Alignment of parameters in multi-line method definition.
21
+ # The `with_fixed_indentation` style aligns the following lines with one
22
+ # level of indentation relative to the start of the line with the method
23
+ # definition.
24
+ #
25
+ # def my_method(a,
26
+ # b)
27
+ Layout/ParameterAlignment:
28
+ EnforcedStyle: with_fixed_indentation
29
+
30
+ # Alignment of parameters in multi-line method call.
31
+ # The `with_fixed_indentation` style aligns the following lines with one
32
+ # level of indentation relative to the start of the line with the method call.
33
+ #
34
+ # my_method(a,
35
+ # b)
36
+ Layout/ArgumentAlignment:
37
+ EnforcedStyle: with_fixed_indentation
38
+
39
+ # a = case n
40
+ # when 0
41
+ # x * 2
42
+ # else
43
+ # y / 3
44
+ # end
45
+ Layout/CaseIndentation:
46
+ EnforcedStyle: end
47
+
48
+ # Enforces a configured order of definitions within a class body
49
+ Layout/ClassStructure:
50
+ Enabled: true
51
+
52
+ # Align `end` with the matching keyword or starting expression except for
53
+ # assignments, where it should be aligned with the LHS.
54
+ Layout/EndAlignment:
55
+ EnforcedStyleAlignWith: variable
56
+ AutoCorrect: true
57
+
58
+ # The `consistent` style enforces that the first element in an array
59
+ # literal where the opening bracket and the first element are on
60
+ # seprate lines is indented the same as an array literal which is not
61
+ # defined inside a method call.
62
+ Layout/FirstArrayElementIndentation:
63
+ EnforcedStyle: consistent
64
+
65
+ # The `consistent` style enforces that the first key in a hash
66
+ # literal where the opening brace and the first key are on
67
+ # seprate lines is indented the same as a hash literal which is not
68
+ # defined inside a method call.
69
+ Layout/FirstHashElementIndentation:
70
+ EnforcedStyle: consistent
71
+
72
+ # Indent multi-line methods instead of aligning with periods
73
+ Layout/MultilineMethodCallIndentation:
74
+ EnforcedStyle: indented
75
+
76
+ # Allow `debug` in tasks for now
77
+ Lint/Debugger:
78
+ Exclude:
79
+ - 'RakeFile'
80
+
81
+ # A calculated magnitude based on number of assignments, branches, and
82
+ # conditions.
83
+ # NOTE: This is temporarily disabled until we can eliminate existing Rubocop
84
+ # complaints
85
+ Metrics/AbcSize:
86
+ Enabled: false
87
+
88
+ # Avoid long blocks with many lines.
89
+ Metrics/BlockLength:
90
+ Exclude:
91
+ - 'RakeFile'
92
+ - 'db/seeds.rb'
93
+ - 'spec/**/*.rb'
94
+
95
+ # Avoid classes longer than 100 lines of code.
96
+ # NOTE: This is temporarily disabled until we can eliminate existing Rubocop
97
+ # complaints
98
+ Metrics/ClassLength:
99
+ Max: 200
100
+ Exclude:
101
+ - 'spec/**/*.rb'
102
+
103
+ # A complexity metric that is strongly correlated to the number of test cases
104
+ # needed to validate a method.
105
+ Metrics/CyclomaticComplexity:
106
+ Max: 9
107
+
108
+ # Limit lines to 80 characters
109
+ Layout/LineLength:
110
+ Exclude:
111
+ - 'RakeFile'
112
+ - 'spec/**/*.rb'
113
+
114
+ # Avoid methods longer than 15 lines of code.
115
+ Metrics/MethodLength:
116
+ Max: 20
117
+ AllowedMethods:
118
+ - swagger_path
119
+ - operation
120
+
121
+
122
+ # A complexity metric geared towards measuring complexity for a human reader.
123
+ Metrics/PerceivedComplexity:
124
+ Max: 10
125
+
126
+ # Naming/FileName:
127
+ # Exclude:
128
+ # - 'lib/file.rb'
129
+
130
+ # Allow `downcase == ` instead of forcing `casecmp`
131
+ Performance/Casecmp:
132
+ Enabled: false
133
+
134
+ # Require children definitions to be nested or compact in classes and modules
135
+ Style/ClassAndModuleChildren:
136
+ Enabled: false
137
+
138
+ # Document classes and non-namespace modules.
139
+ # (Disabled for now, may revisit later)
140
+ Style/Documentation:
141
+ Enabled: false
142
+
143
+ # Checks the formatting of empty method definitions.
144
+ Style/EmptyMethod:
145
+ EnforcedStyle: expanded
146
+
147
+ # Add the frozen_string_literal comment to the top of files to help transition
148
+ # to frozen string literals by default.
149
+ Style/FrozenStringLiteralComment:
150
+ EnforcedStyle: always
151
+
152
+ # Check for conditionals that can be replaced with guard clauses
153
+ Style/GuardClause:
154
+ Enabled: false
155
+
156
+ Style/MixinUsage:
157
+ Exclude:
158
+ - 'RakeFile'
159
+
160
+ # Avoid multi-line method signatures.
161
+ Style/MultilineMethodSignature:
162
+ Enabled: true
163
+
164
+ # Don't use option hashes when you can use keyword arguments.
165
+ Style/OptionHash:
166
+ Enabled: true
167
+
168
+ # Use return instead of return nil.
169
+ Style/ReturnNil:
170
+ Enabled: true
171
+
172
+ # Allow code like `return x, y` as it's occasionally handy.
173
+ Style/RedundantReturn:
174
+ AllowMultipleReturnValues: true
175
+
176
+ # Prefer symbols instead of strings as hash keys.
177
+ Style/StringHashKeys:
178
+ Enabled: true
179
+
180
+ # Checks if configured preferred methods are used over non-preferred.
181
+ Style/StringMethods:
182
+ Enabled: true
183
+
184
+ # Checks for use of parentheses around ternary conditions.
185
+ Style/TernaryParentheses:
186
+ EnforcedStyle: require_parentheses_when_complex
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [1.0.0] - 2022-10-02
2
+
3
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at web.gma@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in immutable_struct_ex_redactable.gemspec
6
+ gemspec
7
+
8
+ gem 'pry-byebug', '~> 3.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'
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ immutable_struct_ex_redactable (1.0.0)
5
+ immutable_struct_ex (~> 0.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ byebug (11.1.3)
12
+ coderay (1.1.3)
13
+ diff-lcs (1.5.0)
14
+ docile (1.4.0)
15
+ immutable_struct_ex (0.3.0)
16
+ jaro_winkler (1.5.4)
17
+ kwalify (0.7.2)
18
+ method_source (1.0.0)
19
+ parallel (1.22.1)
20
+ parser (3.1.2.1)
21
+ ast (~> 2.4.1)
22
+ pry (0.14.1)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
+ pry-byebug (3.10.1)
26
+ byebug (~> 11.0)
27
+ pry (>= 0.13, < 0.15)
28
+ rainbow (3.1.1)
29
+ rake (13.0.6)
30
+ reek (6.1.1)
31
+ kwalify (~> 0.7.0)
32
+ parser (~> 3.1.0)
33
+ 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)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.11.0)
44
+ rspec-mocks (3.11.1)
45
+ 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)
50
+ parallel (~> 1.10)
51
+ parser (>= 2.7.0.1)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ rexml
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (>= 1.4.0, < 2.0)
56
+ ruby-progressbar (1.11.0)
57
+ simplecov (0.21.2)
58
+ docile (~> 1.1)
59
+ simplecov-html (~> 0.11)
60
+ simplecov_json_formatter (~> 0.1)
61
+ simplecov-html (0.12.3)
62
+ simplecov_json_formatter (0.1.4)
63
+ unicode-display_width (1.8.0)
64
+
65
+ PLATFORMS
66
+ x86_64-darwin-19
67
+
68
+ DEPENDENCIES
69
+ immutable_struct_ex_redactable!
70
+ pry-byebug (~> 3.9)
71
+ rake (~> 13.0)
72
+ reek (~> 6.1, >= 6.1.1)
73
+ rspec (~> 3.0)
74
+ rubocop (~> 0.81.0)
75
+ simplecov (~> 0.21.2)
76
+
77
+ BUNDLED WITH
78
+ 2.3.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 gangelo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # `immutable_struct_ex_redactable`
2
+
3
+ [![GitHub version](http://badge.fury.io/gh/gangelo%2Fimmutable_struct_ex_redactable.svg)](https://badge.fury.io/gh/gangelo%2Fimmutable_struct_ex_redactable)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/immutable_struct_ex_redactable.svg)](https://badge.fury.io/rb/immutable_struct_ex_redactable)
6
+
7
+ [![](http://ruby-gem-downloads-badge.herokuapp.com/immutable_struct_ex_redactable?type=total)](http://www.rubydoc.info/gems/immutable_struct_ex_redactable/)
8
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/immutable_struct_ex_redactable/)
9
+
10
+ [![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](https://github.com/gangelo/immutable_struct_ex_redactable/issues)
11
+
12
+ [![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)
13
+
14
+ ## Introduction
15
+
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
+
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
+
20
+ ## Usage
21
+
22
+ Follow the instructions for [Installation](#installation) first, to incorporate this gem into your code.
23
+
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
+ ### Basic usage
29
+
30
+ #### Configure Gem Global Defaults
31
+
32
+ *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:
33
+
34
+ ```ruby
35
+ ImmutableStructExRedactable::configure do |config|
36
+ config.redacted = %i[password dob ssn phone]
37
+ config.redacted_label = '[REDACTED]'
38
+ end
39
+
40
+ fields = {
41
+ first: 'John',
42
+ last: 'Smith',
43
+ password: 'p@ssw0rd',
44
+ dob: '1986-05-12'
45
+ }
46
+
47
+ ImmutableStructExRedactable.create(**fields)
48
+ => #<struct first="John", last="Smith", password="[REDACTED]", dob="[REDACTED]">
49
+
50
+ fields = {
51
+ first: 'Jane',
52
+ last: 'Smith',
53
+ password: 'h3l10W04lD',
54
+ dob: '1990-12-26'
55
+ }
56
+
57
+ ImmutableStructExRedactable.create(**fields)
58
+ => #<struct first="Jane", last="Smith", password="[REDACTED]", dob="[REDACTED]">
59
+
60
+ ```
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
+
63
+ #### Overriding the Global Configuration Operions
64
+
65
+ To override the global configuration options, you may do so by calling the `ImmutableStructExRedactable#create_with` method in the following manner:
66
+
67
+ ```ruby
68
+ # Create a custom configuration with the options you want to use.
69
+ custom_config = ImmutableStructExRedactable::Configuration.new.tap do |config|
70
+ config.redacted = %i[password dob]
71
+ config.redacted_label = '[NO WAY JOSE]'
72
+ end
73
+
74
+ fields = {
75
+ first: 'John',
76
+ last: 'Smith',
77
+ password: 'p@ssw0rd',
78
+ dob: '1986-05-12'
79
+ }
80
+
81
+ # Call the #create_with method passing the custom configuration options.
82
+ ImmutableStructExRedactable.create_with(custom_config, **fields)
83
+ => #<struct first="John", last="Smith", password="[NO WAY JOSE]", dob="[NO WAY JOSE]">
84
+ ```
85
+
86
+ ### &blocks are Permitted
87
+
88
+ 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:
89
+
90
+ ```ruby
91
+ fields = { first: 'John', last: 'Smith', password: 'p@ssw0rd' }
92
+
93
+ struct = ImmutableStructExRedactable.create(**fields) do
94
+ def full_name
95
+ "#{first} #{last}"
96
+ end
97
+ end
98
+
99
+ struct.full_name
100
+ => "John Smith"
101
+ ```
102
+
103
+ ### Miscellaneous Examples
104
+
105
+ ```ruby
106
+ class MyRedactableImmutableStruct
107
+ include ImmutableStructExRedactable
108
+
109
+ class << self
110
+ def create
111
+ self.new.send(:execute)
112
+ end
113
+ end
114
+
115
+ private
116
+
117
+ attr_reader :results
118
+
119
+ def execute
120
+ @results ||= create_with(config, username: 'jsmith', password: 'p@ssw0rd') do
121
+ def jsmith?
122
+ username == 'jsmith'
123
+ end
124
+ end
125
+ end
126
+
127
+ def config
128
+ @config ||= ImmutableStructExRedactable::Configuration.new.tap do |config|
129
+ config.redacted = %i[password]
130
+ config.redacted_label = 'xxxxxx'
131
+ end
132
+ end
133
+ end
134
+
135
+ results = MyRedactableImmutableStruct.create
136
+ #=> #<struct username="jsmith", password="xxxxxx">
137
+
138
+ results.jsmith?
139
+ #=> true
140
+ ```
141
+
142
+ ## Installation
143
+
144
+ Add this line to your application's Gemfile:
145
+
146
+ ```ruby
147
+ gem 'immutable_struct_ex_redactable'
148
+ ```
149
+
150
+ And then execute:
151
+
152
+ $ bundle install
153
+
154
+ Or install it yourself as:
155
+
156
+ $ gem install immutable_struct_ex_redactable
157
+
158
+ ## Development
159
+
160
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
161
+
162
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
163
+
164
+ ## Contributing
165
+
166
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/immutable_struct_ex_redactable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/immutable_struct_ex_redactable/blob/main/CODE_OF_CONDUCT.md).
167
+
168
+ ## License
169
+
170
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
171
+
172
+ ## Code of Conduct
173
+
174
+ Everyone interacting in the ImmutableStructExRedactable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/immutable_struct_ex_redactable/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'immutable_struct_ex_redactable'
6
+ require 'immutable_struct_ex_redactable/configuration'
7
+
8
+ require 'pry-byebug'
9
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
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 and provides redaction.'
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
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is the configuration for ImmutableStructExRedactable.
4
+ module ImmutableStructExRedactable
5
+ class << self
6
+ attr_reader :configuration
7
+
8
+ # Returns the application configuration object.
9
+ #
10
+ # @return [Configuration] the application Configuration object.
11
+ def configure
12
+ self.configuration ||= Configuration.new
13
+
14
+ yield(configuration) if block_given?
15
+
16
+ configuration
17
+ end
18
+
19
+ private
20
+
21
+ attr_writer :configuration
22
+ end
23
+
24
+ # This class encapsulates the configuration properties for this gem and
25
+ # provides methods and attributes that allow for management of the same.
26
+ class Configuration
27
+ # Gets/sets the fields that should be redacted for this gem.
28
+ #
29
+ # The default is %i[password].
30
+ #
31
+ # @return [Array<Symbol>] an Array of Symbols that should be redacted.
32
+ attr_accessor :redacted
33
+
34
+ # Gets/sets the label that should replace redacted field values.
35
+ #
36
+ # The default is "******".
37
+ #
38
+ # @return [String] the label that should replace redacted field values.
39
+ attr_accessor :redacted_label
40
+
41
+ # The constructor; calls {#reset}.
42
+ def initialize
43
+ reset
44
+ end
45
+
46
+ # Resets the configuration settings to their default values.
47
+ #
48
+ # @return [void]
49
+ def reset
50
+ @redacted = %i[password]
51
+ @redacted_label = '******'
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ImmutableStructExRedactable
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'immutable_struct_ex'
4
+ require_relative 'immutable_struct_ex_redactable/configuration'
5
+ require_relative 'immutable_struct_ex_redactable/version'
6
+
7
+ module ImmutableStructExRedactable
8
+ module_function
9
+
10
+ def create(**hash, &block)
11
+ config = ImmutableStructExRedactable.configure
12
+ create_with(config, **hash, &block)
13
+ end
14
+
15
+ def create_with(config, **hash, &block)
16
+ config.redacted.each do |attr|
17
+ next unless hash.key? attr
18
+
19
+ hash[attr] = config.redacted_label
20
+ end
21
+
22
+ ImmutableStructEx.new(**hash, &block)
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module ImmutableStructExRedactable
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: immutable_struct_ex_redactable
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gene M. Angelo, Jr.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: immutable_struct_ex
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ description: Creates and initializes an immutable struct in one and provides redaction.
28
+ email:
29
+ - public.gma@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - ".ruby-version"
37
+ - CHANGELOG.md
38
+ - CODE_OF_CONDUCT.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - immutable_struct_ex_redactable.gemspec
47
+ - lib/immutable_struct_ex_redactable.rb
48
+ - lib/immutable_struct_ex_redactable/configuration.rb
49
+ - lib/immutable_struct_ex_redactable/version.rb
50
+ - sig/immutable_struct_ex_redactable.rbs
51
+ homepage: https://github.com/gangelo/immutable_struct_ex_redactable
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/gangelo/immutable_struct_ex_redactable
56
+ source_code_uri: https://github.com/gangelo/immutable_struct_ex_redactable
57
+ changelog_uri: https://github.com/gangelo/immutable_struct_ex_redactable/blob/main/CHANGELOG.md
58
+ rubygems_mfa_required: 'true'
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.0.1
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.3.22
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: The redactable version of the immutable_stuct_ex gem.
78
+ test_files: []