dorian-json-deep-map 0.0.3 → 1.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 +4 -4
  2. data/bin/json-deep-map +35 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db2aa7e97b26838e9710a88cc9743960d0bd1c3282eb9e199f91657918eb9583
4
- data.tar.gz: 22faaeb6b07adf91ecc682b7ec23158b334346de8dd765a37dce9ea04815c7c7
3
+ metadata.gz: 01d8400654c8a7ab7fab8be8a7371b4b13be998fd6aea2febcb4e424ab04703b
4
+ data.tar.gz: 83b41fbc2f9a32e9375a9bbb9b29243bac6b6dec3da89801c46c6179dc940d58
5
5
  SHA512:
6
- metadata.gz: 8fa7ad17cafb87fbc54fdf655b822b0ba78006dc196b1fd12f42432ed61efec89f9953abbb5ceccd680691cf8a2e5e53e27511527990f82a027622a65fdc6c58
7
- data.tar.gz: d43f78f07c5b91fd4979239b5d283cd9923a9239659aaf47810b9544b500a78b22c2a90cdc2587aa9843a9d21c283061dae488c0e3ce5f67414a9722ef26c149
6
+ metadata.gz: 40161acd5cfcf7ff97665d69abd5fca04fca2bd316d97be03ab4ab03d5d4e09e92fbb3e23fbf77ed247dd522dc2461a1cb56a13d6d5798d9086f2ad2b5fd040a
7
+ data.tar.gz: ec2b9640d114d357b37019ca1aa0f007c3c0ab2c64f6ea1ea825e6f4ecf318b16887d324abf5c03ee333532b8841294d8cc24d3d6d061e0f29ba6802c223f3ed
data/bin/json-deep-map CHANGED
@@ -1,12 +1,41 @@
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 "dorian/to_struct"
6
+ require "json"
7
+
8
+ def deep_map(json, &block)
9
+ json = yield(json.to_deep_struct).from_deep_struct
10
+
11
+ if json.is_a?(Hash)
12
+ json.to_h { |key, value| deep_map([key, value], &block) }
13
+ elsif json.is_a?(Array)
14
+ json.map { |element| deep_map(element, &block) }
15
+ else
16
+ json
17
+ end
7
18
  end
8
19
 
9
- $stdin.each_line do |it|
10
- it.strip!
11
- eval(ARGV.first)
20
+ parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
21
+
22
+ abort parsed.help if parsed.options.help
23
+
24
+ if parsed.options.version
25
+ abort File.read(File.expand_path("../../VERSION", __FILE__))
26
+ end
27
+
28
+ inputs = parsed.files.map { |file| File.read(file) }
29
+ inputs = [$stdin.each_line.to_a.map(&:strip).join("\n")] if inputs.empty?
30
+
31
+ inputs.each do |input|
32
+ puts(
33
+ JSON.pretty_generate(
34
+ deep_map(JSON.parse(input)) do |it|
35
+ it = it.dup
36
+ eval(parsed.arguments.join(" "))
37
+ it
38
+ end
39
+ )
40
+ )
12
41
  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.3
4
+ version: 1.1.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-22 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