redacted_struct 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 33437d1b7be19f014678f6bdeab2900bc2e0d179699e2a5f5fd4e4cbe107b4f2
4
+ data.tar.gz: 5d3ad99adb60ffe21be6d1a172adc5f79374c82337e178a96e2b50a7a6f2f2b4
5
+ SHA512:
6
+ metadata.gz: efb6986ea192e32bf37e2da288f219060eef31331840b321bdf09da14845a690bb217177237a3be73314b4c844a0836ff95a566eda51efd365e3871fcfb786b1
7
+ data.tar.gz: 38d2b23615e693b268804970a23d6840cda13019de0b12c7e3a7a553cc7fcffda65fd2c4f9c53ccc62173eba3ebc1afca8c7a379ebf8c29e1e2ea3396a5985c4
@@ -0,0 +1,18 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.1.2
4
+
5
+ jobs:
6
+ build:
7
+ docker:
8
+ - image: cimg/ruby:2.6.5
9
+ executor: ruby/default
10
+ steps:
11
+ - checkout
12
+ - run:
13
+ name: Which bundler?
14
+ command: bundle -v
15
+ - ruby/bundle-install
16
+ - run:
17
+ name: Run specs
18
+ command: bundle exec rake spec
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: disable
4
+ SuggestExtensions: false
5
+
6
+ Style/Alias:
7
+ Enabled: false
8
+
9
+ Style/StringLiterals:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Style/StringLiteralsInInterpolation:
14
+ Enabled: true
15
+ EnforcedStyle: double_quotes
16
+
17
+ Style/SymbolArray:
18
+ Enabled: false
19
+
20
+ Style/TrailingCommaInArguments:
21
+ EnforcedStyleForMultiline: comma
22
+
23
+ Layout/LineLength:
24
+ Max: 120
25
+
26
+ Metrics/BlockLength:
27
+ Exclude:
28
+ - "spec/**/*.rb"
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2021-03-24
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in redacted_struct.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "rubocop", "~> 1.7"
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # RedactedStruct
2
+
3
+ A version of Ruby's built-in Struct that redacts members when printing, and can allow specifying
4
+ members that can be printed normally (an allowlist).
5
+
6
+ ```ruby
7
+ Config = RedactedStruct.new(
8
+ :username,
9
+ :password,
10
+ :timeout,
11
+ keyword_init: true,
12
+ allowed_members: [:username, :timeout]
13
+ )
14
+
15
+ Config.new(username: 'example', password: 'secret', timeout: 5)
16
+ => #<struct Config username="example" password=[REDACTED] timeout=5>
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'redacted_struct'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle install
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install redacted_struct
34
+
35
+ ## Development
36
+
37
+ 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.
38
+
39
+ 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).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/zachmargolis/redacted_struct.
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,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "redacted_struct"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
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,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A subclass of Struct that redacts members by default, and can allow some to be printed
4
+ class RedactedStruct < Struct
5
+ VERSION = "1.0.0"
6
+
7
+ def self.new(*name_and_members, keyword_init: nil, allowed_members: [], &block)
8
+ super(*name_and_members, keyword_init: keyword_init, &block).tap do |struct_class|
9
+ struct_class.class_eval do
10
+ @allowed_members = Array(allowed_members)
11
+ end
12
+ end
13
+ end
14
+
15
+ class << self
16
+ attr_reader :allowed_members
17
+ end
18
+
19
+ def allowed_members
20
+ self.class.allowed_members
21
+ end
22
+
23
+ def inspect
24
+ name_or_nil = self.class.name ? " #{self.class.name}" : nil
25
+
26
+ attributes = members.map do |member|
27
+ if allowed_members.include?(member)
28
+ "#{member}=#{self[member].inspect}"
29
+ else
30
+ "#{member}=[REDACTED]"
31
+ end
32
+ end.join(" ")
33
+
34
+ "#<struct#{name_or_nil} #{attributes}>"
35
+ end
36
+
37
+ alias_method :to_s, :inspect
38
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/redacted_struct"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "redacted_struct"
7
+ spec.version = RedactedStruct::VERSION
8
+ spec.authors = ["Zach Margolis"]
9
+
10
+ spec.summary = "A Ruby Struct that can be redacted"
11
+ spec.description = "Help prevent logging sensitive by accident"
12
+ spec.homepage = "https://github.com/zachmargolis/redacted_struct"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = "https://github.com/zachmargolis/redacted_struct/blob/main/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ # Uncomment to register a new dependency of your gem
29
+ # spec.add_dependency "example-gem", "~> 1.0"
30
+
31
+ # For more information and examples about making a new gem, checkout our
32
+ # guide at: https://bundler.io/guides/creating_gem.html
33
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redacted_struct
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Zach Margolis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Help prevent logging sensitive by accident
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".circleci/config.yml"
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - Gemfile
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/redacted_struct.rb
30
+ - redacted_struct.gemspec
31
+ homepage: https://github.com/zachmargolis/redacted_struct
32
+ licenses: []
33
+ metadata:
34
+ homepage_uri: https://github.com/zachmargolis/redacted_struct
35
+ source_code_uri: https://github.com/zachmargolis/redacted_struct
36
+ changelog_uri: https://github.com/zachmargolis/redacted_struct/blob/main/CHANGELOG.md
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.1.2
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: A Ruby Struct that can be redacted
56
+ test_files: []