dorian-anonymize-json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/anonymize-json +47 -0
  3. metadata +62 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b78a46795d6921a2142115f0f08420643eeda864651145cc424762321e8a1f87
4
+ data.tar.gz: 179aae0ba279126b9ca76cecfc97ed356bd75b81b6069c30d843e8e055a32fda
5
+ SHA512:
6
+ metadata.gz: 87e6885624b0d0325adc0c69bdf30cf70c35157b2bc5a4d0b822620c058117fc2b47c71d2af5ae48f53cc2cb1bc593823f23dc8a58108ae06c1fbf4ffdf8540a
7
+ data.tar.gz: d9be58723ca1b53a3792bb389606d5dd1d5b9ae0a449be1a771204be15319454e828cedc61b1981061f37c2e1c47d77544f2aea88b8fba0ccbe130eb8d007174
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "json"
5
+
6
+ def anonymize_json(data)
7
+ if data.is_a?(Array)
8
+ data.map { |element| anonymize_json(element) }
9
+ elsif data.is_a?(Hash)
10
+ data.transform_values { |value| anonymize_json(value) }
11
+ elsif data.is_a?(String)
12
+ data.gsub(/[0-9]/, "0").gsub(/[a-z]/, "a").gsub(/[A-Z]/, "A")
13
+ elsif data.is_a?(Integer)
14
+ 0
15
+ elsif data.is_a?(Float)
16
+ 0.0
17
+ elsif data.is_a?(TrueClass) || data.is_a?(FalseClass)
18
+ false
19
+ else
20
+ raise NotImplementedError, data.class.name
21
+ end
22
+ end
23
+
24
+ if ARGV[0] == "--help" || ARGV[0] == "-h"
25
+ puts "USAGE: anonymize-yaml FILES..."
26
+ puts "USAGE: ... | anonymize-yaml"
27
+ exit
28
+ end
29
+
30
+ inputs = ARGV
31
+
32
+ if inputs.empty?
33
+ inputs = $stdin.each_line.to_a
34
+
35
+ inputs =
36
+ if File.exist?(inputs.first.strip)
37
+ inputs.map(&:strip)
38
+ else
39
+ [inputs.join]
40
+ end
41
+ end
42
+
43
+ inputs.each do |input|
44
+ content = File.exist?(input) ? File.read(input) : input
45
+ json = JSON.pretty_generate(anonymize_json(JSON.parse(content)))
46
+ File.exist?(input) ? File.write(input, json) : puts(json)
47
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dorian-anonymize-json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dorian Marié
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ description: |-
28
+ Anonymize JSON file
29
+
30
+ e.g. `anonymize-json spec/**/*.json`
31
+ email: dorian@dorianmarie.com
32
+ executables:
33
+ - anonymize-json
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - bin/anonymize-json
38
+ homepage: https://github.com/dorianmariecom/anonymize-json
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ rubygems_mfa_required: 'true'
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.5.3
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Anonymize JSON file
62
+ test_files: []