dorian-json-deep-map 0.0.2 → 1.0.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 +4 -4
  2. data/bin/json-deep-map +32 -6
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1845c24fadb2d81663df41b6a44fae44f75c1e5fe8024ee92e0adca1a160f58
4
- data.tar.gz: faca85fd1a70d875fdaffda71fbc85d057b8790c3a2fd1d57708d13b97b1ff44
3
+ metadata.gz: 321de00122085b3493353f9e1d6acca4c52a06ba0894380b450a8a5784e81fb7
4
+ data.tar.gz: fa5ffbd105eaca9dfde0ff5ebd9b756b81b07352b1d84fc2fce4c8c42c3d14f3
5
5
  SHA512:
6
- metadata.gz: c8ae7d7af3bc402a256b74f83a93c249b5956e45d229c19fd52087e8639cce27c505b8dca6d88941f0a1714100bc653398e25dbbd289bcc448e58253cea00c25
7
- data.tar.gz: 9c5d87718423eb5af4eed314e45e1c75f6c940b9c172a0f4f64790a03f484d7c445a3f18a03801ba355a98b26ca16ab1bee67f039cb77f583e1228a156a26c0e
6
+ metadata.gz: 6514093a5eb3f50c87d56d94b798c4ed0c2261f634eb092cd57c742a6576394b5ffdeaf00c1a2423fe87e328899ae7cc358f957f9a748649dff8f26c47d55852
7
+ data.tar.gz: 4c75b89fdaa9bf76fb6a211b20dab768429e44b153bbad288e2603d8ada7a98fdab32cdd71e79c61a67227ddc47c33e583bc958d5047033d46299b1d93b832c0
data/bin/json-deep-map CHANGED
@@ -1,12 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- if ARGV.size != 1 || ARGV[0] == "--help" || ARGV[0] == "-h"
5
- puts "USAGE: ... | each CODE"
6
- exit
4
+ require "dorian/arguments"
5
+ require "json"
6
+
7
+ def deep_map(json, &block)
8
+ if json.is_a?(Hash)
9
+ yield(json).to_h { |key, value| deep_map([key, value], &block) }
10
+ elsif json.is_a?(Array)
11
+ yield(json).map { |element| deep_map(element, &block) }
12
+ else
13
+ yield(json)
14
+ end
15
+ end
16
+
17
+ parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
18
+
19
+ abort parsed.help if parsed.options.help
20
+
21
+ if parsed.options.version
22
+ abort File.read(File.expand_path("../../VERSION", __FILE__))
7
23
  end
8
24
 
9
- $stdin.each_line do |it|
10
- it.strip!
11
- eval(ARGV.first)
25
+ inputs = parsed.files.map { |file| File.read(file) }
26
+ inputs = [$stdin.each_line.to_a.map(&:strip).join("\n")] if inputs.empty?
27
+
28
+ inputs.each do |input|
29
+ puts(
30
+ JSON.pretty_generate(
31
+ deep_map(JSON.parse(input)) do |it|
32
+ it = it.dup
33
+ eval(parsed.arguments.join(" "))
34
+ it
35
+ end
36
+ )
37
+ )
12
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-json-deep-map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-18 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dorian-arguments
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: evaluates ruby code on deep each of json to map to another json
42
56
  email: dorian@dorianmarie.com
43
57
  executables: