scrawl 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scrawl.rb +6 -3
- data/lib/scrawl/version.rb +1 -1
- data/spec/lib/scrawl_spec.rb +24 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fae72114f1a7396cc0e541f34ab73c3e005af43
|
4
|
+
data.tar.gz: edf0916f009bd56ec5a8225aaf086d8de5326b93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae0b61376227d10149e3f7fef6289344748c06293202ed03028672b24248ce925bfeee6186f1fb0b5747b77888bd2b29c2ee9aaca8956789bdb350768349ce11
|
7
|
+
data.tar.gz: 03e82b8abc0c119748b305f448f9bb2ecda76419afa2696d28b0d638325c028773396c1b5b411d015078fe87bc003bc0d96f95d06a9a56f307b08a446862ed6b
|
data/lib/scrawl.rb
CHANGED
@@ -17,10 +17,13 @@ class Scrawl
|
|
17
17
|
|
18
18
|
def inspect(namespace = nil)
|
19
19
|
@tree.map do |key, value|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
case
|
21
|
+
when value.kind_of?(Hash) && value.none?
|
22
|
+
label(namespace, key) + KEY_VALUE_DELIMITER + element(nil)
|
23
|
+
when value.respond_to?(:to_hash)
|
23
24
|
Scrawl.new(value).inspect(key)
|
25
|
+
else
|
26
|
+
label(namespace, key) + KEY_VALUE_DELIMITER + element(value)
|
24
27
|
end
|
25
28
|
end.join(PAIR_DELIMITER)
|
26
29
|
end
|
data/lib/scrawl/version.rb
CHANGED
data/spec/lib/scrawl_spec.rb
CHANGED
@@ -41,10 +41,6 @@ RSpec.describe Scrawl do
|
|
41
41
|
context "scrawl objects" do
|
42
42
|
let(:trees) { [Scrawl.new(a: 1), Scrawl.new(b: 2)] }
|
43
43
|
end
|
44
|
-
|
45
|
-
context "hash and scrawl objects" do
|
46
|
-
|
47
|
-
end
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
@@ -84,41 +80,55 @@ RSpec.describe Scrawl do
|
|
84
80
|
let(:input) { { a: "example" } }
|
85
81
|
|
86
82
|
it "includes the escaped text" do
|
87
|
-
expect(inspect).to
|
83
|
+
expect(inspect).to eq("a=\"example\"")
|
88
84
|
end
|
89
85
|
end
|
90
86
|
|
91
87
|
context "and a proc value" do
|
92
|
-
let(:input) { { a: -> { "example#{
|
88
|
+
let(:input) { { a: -> { "example#{1 + 1}" } } }
|
93
89
|
|
94
90
|
it "evaluate the proc" do
|
95
|
-
expect(inspect).to
|
91
|
+
expect(inspect).to eq("a=\"example2\"")
|
96
92
|
end
|
97
93
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
94
|
+
context "with a random portion" do
|
95
|
+
let(:input) { { a: -> { "example#{rand(1..100000)}" } } }
|
96
|
+
|
97
|
+
it "never stores the value" do
|
98
|
+
first = scrawl.inspect
|
99
|
+
second = scrawl.inspect
|
100
|
+
expect(first).to_not eq(second)
|
101
|
+
end
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
context "and a number value" do
|
106
106
|
it "returns just the number" do
|
107
|
-
expect(inspect).to
|
107
|
+
expect(inspect).to eq("a=1")
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
context "and a symbol value" do
|
112
112
|
let(:input) { { a: :example } }
|
113
|
+
|
113
114
|
it "returns the escaped string equivelent" do
|
114
|
-
expect(inspect).to
|
115
|
+
expect(inspect).to eq("a=\"example\"")
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
118
119
|
context "and a regexp value" do
|
119
120
|
let(:input) { { a: /foo(.+)/ } }
|
121
|
+
|
120
122
|
it "returns the escaped regexp" do
|
121
|
-
expect(inspect).to
|
123
|
+
expect(inspect).to eq("a=/foo(.+)/")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "and a hash" do
|
128
|
+
let(:input) { { a: Hash.new } }
|
129
|
+
|
130
|
+
it "returns as if nil" do
|
131
|
+
expect(inspect).to eq("a=nil")
|
122
132
|
end
|
123
133
|
end
|
124
134
|
end
|