jsontrim 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/jsontrim.gemspec +1 -1
- data/lib/jsontrim.rb +4 -5
- data/test/jsontrim_test.rb +12 -12
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/jsontrim.gemspec
CHANGED
data/lib/jsontrim.rb
CHANGED
@@ -51,10 +51,9 @@ class JSONTrim
|
|
51
51
|
end
|
52
52
|
|
53
53
|
js = JSON.pretty_generate(obj)
|
54
|
-
js = js.gsub('"IGN_HSH"', "{
|
55
|
-
js = js.gsub('"IGN_ARY"', "[
|
56
|
-
js = js.gsub('"
|
57
|
-
js = js.gsub('"IGN"', '"..."')
|
54
|
+
js = js.gsub('"IGN_HSH"', "{ ... }")
|
55
|
+
js = js.gsub('"IGN_ARY"', "[ ... ]")
|
56
|
+
js = js.gsub('"IGN"', "...")
|
58
57
|
end
|
59
58
|
|
60
59
|
# recursively prune the current ruby object with the given rules
|
@@ -77,7 +76,7 @@ class JSONTrim
|
|
77
76
|
end if data[name]
|
78
77
|
elsif key =~ /^\+$/
|
79
78
|
if Array === data
|
80
|
-
data = [data.first, "
|
79
|
+
data = [data.first, "IGN"]
|
81
80
|
end
|
82
81
|
elsif key =~ /^\*$/
|
83
82
|
if Array === data
|
data/test/jsontrim_test.rb
CHANGED
@@ -22,35 +22,35 @@ class JsontrimTest < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
should "distinguish between arrays and hashes" do
|
25
|
-
assert_equal %Q({\n "foo": {
|
25
|
+
assert_equal %Q({\n "foo": { ... }\n}),
|
26
26
|
JSONTrim.cut(%q({"foo" : { "bar": "fred"}}), :ignore => ["!foo"])
|
27
|
-
assert_equal %Q({\n "foo": [
|
27
|
+
assert_equal %Q({\n "foo": [ ... ]\n}),
|
28
28
|
JSONTrim.cut(%q({"foo" : [ "bar", "fred"]}), :ignore => ["!foo"])
|
29
|
-
assert_equal %Q({\n "foo":
|
29
|
+
assert_equal %Q({\n "foo": ...\n}),
|
30
30
|
JSONTrim.cut(%q({"foo" : 3}), :ignore => ["!foo"])
|
31
31
|
end
|
32
32
|
|
33
33
|
should "work for nested attributes" do
|
34
|
-
assert_equal %Q({\n "foo": {\n "bar": {
|
34
|
+
assert_equal %Q({\n "foo": {\n "bar": { ... }\n }\n}),
|
35
35
|
JSONTrim.cut(%q({"foo" : { "bar": {"f":3}}}), :ignore => ["foo:!bar"])
|
36
36
|
|
37
|
-
assert_equal %Q({\n "foo": {\n "bar":
|
37
|
+
assert_equal %Q({\n "foo": {\n "bar": ...\n }\n}),
|
38
38
|
JSONTrim.cut(%q({"foo" : { "bar": 3}}), :ignore => ["foo:!bar"])
|
39
39
|
end
|
40
40
|
|
41
41
|
should "not alter json if ignored thing does not exist" do
|
42
|
-
assert_equal %Q({\n "foo": {
|
42
|
+
assert_equal %Q({\n "foo": { ... }\n}),
|
43
43
|
JSONTrim.cut(%q({"foo" : { "bar": "fred"}}),
|
44
44
|
:ignore => ["!foo", "!doesnotexist", "foo:!doesnotexist"])
|
45
45
|
end
|
46
46
|
|
47
47
|
should "allow ignoring of subelements of arrays" do
|
48
|
-
assert_equal_ws %Q({"foo":[{"bar": {
|
48
|
+
assert_equal_ws %Q({"foo":[{"bar": { ... }},{"bar": ...}]}),
|
49
49
|
JSONTrim.cut(%q({"foo" : [{ "bar": {"baz":3}}, {"bar":3}]}), :ignore => ["foo:*:!bar"])
|
50
50
|
end
|
51
51
|
|
52
52
|
should "allow ignoring of arrays" do
|
53
|
-
assert_equal %Q({\n "foo": [\n "bar",\n
|
53
|
+
assert_equal %Q({\n "foo": [\n "bar",\n ...\n ]\n}),
|
54
54
|
JSONTrim.cut(%q({"foo": ["bar", "baz", "fred"]}),
|
55
55
|
:ignore => ["foo:+"])
|
56
56
|
end
|
@@ -73,18 +73,18 @@ class JsontrimTest < Test::Unit::TestCase
|
|
73
73
|
expected = <<-EOF
|
74
74
|
{
|
75
75
|
"foo": {
|
76
|
-
"two":
|
76
|
+
"two": ...,
|
77
77
|
"three": {
|
78
|
-
"b": [
|
78
|
+
"b": [ ... ]
|
79
79
|
},
|
80
80
|
"one": {
|
81
81
|
"a": 1,
|
82
|
-
"b": {
|
82
|
+
"b": { ... }
|
83
83
|
}
|
84
84
|
},
|
85
85
|
"bar": [
|
86
86
|
1,
|
87
|
-
|
87
|
+
...
|
88
88
|
]
|
89
89
|
}
|
90
90
|
EOF
|