-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjolt.rb
77 lines (71 loc) · 1.85 KB
/
jolt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class Jolt < Formula
desc "JSON to JSON transformation library and cli written in java"
homepage "https://bazaarvoice.github.io/jolt/"
url "http://search.maven.org/remotecontent?filepath=com/bazaarvoice/jolt/jolt-cli/0.0.24/jolt-cli-0.0.24.jar"
sha256 "5a4bf4afb8bd01154aa2bcf89bde87a1b2623ae8b6901893a4d9f1a291689bbf"
depends_on :java
def install
libexec.install "jolt-cli-#{version}.jar"
bin.write_jar_script libexec/"jolt-cli-#{version}.jar", "jolt", "$JAVA_OPTS"
end
test do
(testpath/"input.json").write <<-EOS.undent
{
"rating": {
"primary": {
"value": 3
},
"quality": {
"value": 3
}
}
}
EOS
(testpath/"jolt_spec.json").write <<-EOS.undent
[
{
"operation": "shift",
"spec": {
"rating": {
"primary": {
"value": "Rating",
"max": "RatingRange"
},
"*": {
"max": "SecondaryRatings.&1.Range",
"value": "SecondaryRatings.&1.Value",
"$": "SecondaryRatings.&1.Id"
}
}
}
},
{
"operation": "default",
"spec": {
"Range": 5,
"SecondaryRatings": {
"*": {
"Range": 5
}
}
}
}
]
EOS
(testpath/"expected_output.json").write <<-EOS.undent
{
"Range" : 5,
"Rating" : 3,
"SecondaryRatings" : {
"quality" : {
"Id" : "quality",
"Range" : 5,
"Value" : 3
}
}
}
EOS
system "#{bin}/jolt transform spec.json input.json > expected_output.json"
system "#{bin}/jolt", "diffy", "output.json", "expected_output.json"
end
end