cornucopia 0.1.49 → 0.1.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cornucopia/util/pretty_formatter.rb +23 -0
- data/lib/cornucopia/version.rb +1 -1
- data/spec/lib/util/pretty_formatter_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7462c271c128c488e2b7678c71196f50c0217a42
|
4
|
+
data.tar.gz: 8e5fdc17a806ccb163cbe85ab12bd8258fc11300
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b93a7e57f64c87e647c64ed76e23535b8ead4a609e789c380218e356089cfb1aeac47fcc7f297d0386a18eff29cca1286f96556f5a55ae5a0c127f1c690170c
|
7
|
+
data.tar.gz: c0861b302f07518b241277ebb89ae0db9d35c92a91df7309e2ca58ce8428ff16665dcb57f024c0dc671ee3e215c29784ea5a236e7ab716d1da76c3c7128c216f
|
@@ -34,6 +34,8 @@ module Cornucopia
|
|
34
34
|
end
|
35
35
|
|
36
36
|
if do_pretty_print
|
37
|
+
@loop_pos = [-1, -1]
|
38
|
+
@loop_count = [0, 0]
|
37
39
|
@indent_level = 0
|
38
40
|
@current_state = :unknown
|
39
41
|
@state_stack = [:unknown]
|
@@ -43,6 +45,8 @@ module Cornucopia
|
|
43
45
|
@formatted_string = "".dup
|
44
46
|
|
45
47
|
while @current_pos < @unknown_string_len
|
48
|
+
break if in_infinite_loop?
|
49
|
+
|
46
50
|
case @current_state
|
47
51
|
when :unknown
|
48
52
|
search_pos = @current_pos
|
@@ -173,6 +177,9 @@ module Cornucopia
|
|
173
177
|
|
174
178
|
when :array
|
175
179
|
group_value_end :array_comma, "]"
|
180
|
+
|
181
|
+
when :group_implied
|
182
|
+
@current_pos += 1
|
176
183
|
end
|
177
184
|
|
178
185
|
@current_pos -= 1
|
@@ -577,6 +584,22 @@ module Cornucopia
|
|
577
584
|
end
|
578
585
|
end
|
579
586
|
end
|
587
|
+
|
588
|
+
private
|
589
|
+
|
590
|
+
def in_infinite_loop?
|
591
|
+
@loop_count[0] += 1
|
592
|
+
@loop_count[1] += 1
|
593
|
+
@loop_count[0] = 0 if @loop_pos[0] != @current_pos
|
594
|
+
@loop_count[1] = 0 if @loop_pos[1] != @start_pos
|
595
|
+
@loop_pos[0] = @current_pos
|
596
|
+
@loop_pos[1] = @start_pos
|
597
|
+
|
598
|
+
return false if @loop_count[0] < @unknown_string_len && @loop_count[1] < @unknown_string_len
|
599
|
+
|
600
|
+
@formatted_string += @unknown_string[@start_pos..-1]
|
601
|
+
true
|
602
|
+
end
|
580
603
|
end
|
581
604
|
end
|
582
605
|
end
|
data/lib/cornucopia/version.rb
CHANGED
@@ -65,6 +65,12 @@ describe Cornucopia::Util::PrettyFormatter do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
it "formats a string" do
|
69
|
+
pretty = Cornucopia::Util::PrettyFormatter.format_string("#<MetaDataOwnerTestModel _id: 5a3ea06e402cfe50bca1fc6b, >\n".html_safe)
|
70
|
+
|
71
|
+
expect(pretty).to eq "#<MetaDataOwnerTestModel\n _id: 5a3ea06e402cfe50bca1fc6b,\n>"
|
72
|
+
end
|
73
|
+
|
68
74
|
it "formats a simple class" do
|
69
75
|
pretty = Cornucopia::Util::PrettyFormatter.format_string(simple_class)
|
70
76
|
expect(pretty).to be == simple_class
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cornucopia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.50
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RealNobody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|