ruby-beautify 0.96.0 → 0.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CONTRIB.md +7 -0
- data/README.md +21 -22
- data/WHATSNEW.md +7 -0
- data/bin/rbeautify +36 -17
- data/bin/ruby-beautify +36 -17
- data/lib/ruby-beautify.rb +146 -144
- data/lib/ruby-beautify/version.rb +1 -1
- data/spec/bin/ruby-beautify_spec.rb +37 -18
- data/spec/binary_scenarios/doubled_example.rb +6 -0
- data/spec/binary_scenarios/overwrite.rb +6 -0
- data/spec/binary_scenarios/overwrite_pretty.rb +6 -0
- data/spec/binary_scenarios/small_example.rb +3 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/usage_scenarios/README.md +44 -0
- data/spec/usage_scenarios/case.rb +11 -0
- data/spec/usage_scenarios/case_pretty.rb +11 -0
- data/spec/usage_scenarios/from_control.rb +17 -0
- data/spec/usage_scenarios/from_control_pretty.rb +17 -0
- data/spec/usage_scenarios/monolithic_example.rb +40 -0
- data/spec/usage_scenarios/monolithic_example_pretty.rb +40 -0
- data/spec/usage_scenarios/multiline_strings.rb +10 -0
- data/spec/usage_scenarios/multiline_strings_pretty.rb +10 -0
- data/spec/usage_scenarios/mutli_level.rb +34 -0
- data/spec/usage_scenarios/mutli_level_pretty.rb +34 -0
- data/spec/usage_scenarios/or_equals.rb +21 -0
- data/spec/usage_scenarios/or_equals_pretty.rb +21 -0
- data/spec/usage_scenarios/pre_indented.rb +12 -0
- data/spec/usage_scenarios/pre_indented_pretty.rb +12 -0
- data/spec/usage_scenarios_spec.rb +20 -0
- metadata +42 -6
- data/spec/example.rb +0 -151
- data/spec/example_beautified.rb +0 -151
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe "Usage Scenarios" do
|
4
|
+
files = Dir.glob("spec/usage_scenarios/*_pretty.rb")
|
5
|
+
scenarios = files.map do |f|
|
6
|
+
r = /.*\/(?<scenario>.*)_pretty.rb/.match(f)
|
7
|
+
r['scenario'] ||= nil
|
8
|
+
end
|
9
|
+
|
10
|
+
scenarios.each do |scenario|
|
11
|
+
it "will test: #{scenario}" do
|
12
|
+
scenario_file = "spec/usage_scenarios/#{scenario}.rb"
|
13
|
+
scenario_md5_sum = Digest::MD5.hexdigest RubyBeautify.pretty_string File.read scenario_file
|
14
|
+
|
15
|
+
scenario_pretty_file = "spec/usage_scenarios/#{scenario}_pretty.rb"
|
16
|
+
scenario_pretty_md5_sum = Digest::MD5.hexdigest File.read(scenario_pretty_file)
|
17
|
+
expect(scenario_md5_sum).to eq scenario_pretty_md5_sum
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-beautify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.97.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Brodeur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -76,9 +76,27 @@ files:
|
|
76
76
|
- lib/ruby-beautify/version.rb
|
77
77
|
- ruby-beautify.gemspec
|
78
78
|
- spec/bin/ruby-beautify_spec.rb
|
79
|
-
- spec/
|
80
|
-
- spec/
|
79
|
+
- spec/binary_scenarios/doubled_example.rb
|
80
|
+
- spec/binary_scenarios/overwrite.rb
|
81
|
+
- spec/binary_scenarios/overwrite_pretty.rb
|
82
|
+
- spec/binary_scenarios/small_example.rb
|
81
83
|
- spec/spec_helper.rb
|
84
|
+
- spec/usage_scenarios/README.md
|
85
|
+
- spec/usage_scenarios/case.rb
|
86
|
+
- spec/usage_scenarios/case_pretty.rb
|
87
|
+
- spec/usage_scenarios/from_control.rb
|
88
|
+
- spec/usage_scenarios/from_control_pretty.rb
|
89
|
+
- spec/usage_scenarios/monolithic_example.rb
|
90
|
+
- spec/usage_scenarios/monolithic_example_pretty.rb
|
91
|
+
- spec/usage_scenarios/multiline_strings.rb
|
92
|
+
- spec/usage_scenarios/multiline_strings_pretty.rb
|
93
|
+
- spec/usage_scenarios/mutli_level.rb
|
94
|
+
- spec/usage_scenarios/mutli_level_pretty.rb
|
95
|
+
- spec/usage_scenarios/or_equals.rb
|
96
|
+
- spec/usage_scenarios/or_equals_pretty.rb
|
97
|
+
- spec/usage_scenarios/pre_indented.rb
|
98
|
+
- spec/usage_scenarios/pre_indented_pretty.rb
|
99
|
+
- spec/usage_scenarios_spec.rb
|
82
100
|
homepage: https://github.com/erniebrodeur/ruby-beautify
|
83
101
|
licenses: []
|
84
102
|
metadata: {}
|
@@ -104,6 +122,24 @@ specification_version: 4
|
|
104
122
|
summary: a cli tool (and module) to beautify ruby code.
|
105
123
|
test_files:
|
106
124
|
- spec/bin/ruby-beautify_spec.rb
|
107
|
-
- spec/
|
108
|
-
- spec/
|
125
|
+
- spec/binary_scenarios/doubled_example.rb
|
126
|
+
- spec/binary_scenarios/overwrite.rb
|
127
|
+
- spec/binary_scenarios/overwrite_pretty.rb
|
128
|
+
- spec/binary_scenarios/small_example.rb
|
109
129
|
- spec/spec_helper.rb
|
130
|
+
- spec/usage_scenarios/README.md
|
131
|
+
- spec/usage_scenarios/case.rb
|
132
|
+
- spec/usage_scenarios/case_pretty.rb
|
133
|
+
- spec/usage_scenarios/from_control.rb
|
134
|
+
- spec/usage_scenarios/from_control_pretty.rb
|
135
|
+
- spec/usage_scenarios/monolithic_example.rb
|
136
|
+
- spec/usage_scenarios/monolithic_example_pretty.rb
|
137
|
+
- spec/usage_scenarios/multiline_strings.rb
|
138
|
+
- spec/usage_scenarios/multiline_strings_pretty.rb
|
139
|
+
- spec/usage_scenarios/mutli_level.rb
|
140
|
+
- spec/usage_scenarios/mutli_level_pretty.rb
|
141
|
+
- spec/usage_scenarios/or_equals.rb
|
142
|
+
- spec/usage_scenarios/or_equals_pretty.rb
|
143
|
+
- spec/usage_scenarios/pre_indented.rb
|
144
|
+
- spec/usage_scenarios/pre_indented_pretty.rb
|
145
|
+
- spec/usage_scenarios_spec.rb
|
data/spec/example.rb
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'ripper'
|
2
|
-
|
3
|
-
module Here
|
4
|
-
class There
|
5
|
-
def why?(argument = nil)
|
6
|
-
@array = [
|
7
|
-
1,
|
8
|
-
2,
|
9
|
-
3
|
10
|
-
]
|
11
|
-
hash = {
|
12
|
-
one:1,
|
13
|
-
two:2,
|
14
|
-
three:3
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
# a comment
|
19
|
-
def why_not?(argument: {})
|
20
|
-
@array = [4,5,6]
|
21
|
-
hash = {four:4, five:5, six:6}
|
22
|
-
s = "a #{"complex"} string."
|
23
|
-
end
|
24
|
-
|
25
|
-
def complex_method(one, two, three, four)
|
26
|
-
regex = /regex/
|
27
|
-
end
|
28
|
-
|
29
|
-
def with_block
|
30
|
-
run = Proc.new { |argument| puts arugment }
|
31
|
-
run do |arugment|
|
32
|
-
puts argument
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
h = Here::There.new
|
39
|
-
|
40
|
-
h.why?({
|
41
|
-
here: 'there',
|
42
|
-
there: 'here'
|
43
|
-
})
|
44
|
-
|
45
|
-
h.with_block {
|
46
|
-
puts 'yahooie'
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
51
|
-
'alfkjsdlkfjsflgkjfglk',
|
52
|
-
'alfkjsdlkfjsflgkjfglk',
|
53
|
-
'alfkjsdlkfjsflgkjfglk'
|
54
|
-
)
|
55
|
-
|
56
|
-
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
57
|
-
'alfkjsdlkfjsflgkjfglk',
|
58
|
-
'alfkjsdlkfjsflgkjfglk',
|
59
|
-
'alfkjsdlkfjsflgkjfglk'
|
60
|
-
).map do |i|
|
61
|
-
i
|
62
|
-
end.map! { |i| i }
|
63
|
-
|
64
|
-
if 1 > 0
|
65
|
-
puts 'something'
|
66
|
-
elsif 1 < 0
|
67
|
-
puts 'never!'
|
68
|
-
else
|
69
|
-
puts 'not likely.'
|
70
|
-
end
|
71
|
-
|
72
|
-
#Test for different if-statement formatting
|
73
|
-
if 1 > 0 then puts 'something'
|
74
|
-
else puts 'nothing' end
|
75
|
-
puts "This line should stay the same"
|
76
|
-
|
77
|
-
# Test for already indented blocks
|
78
|
-
class There2 < There
|
79
|
-
def m1()
|
80
|
-
puts "m1"
|
81
|
-
end
|
82
|
-
def m2()
|
83
|
-
puts "m2"
|
84
|
-
end
|
85
|
-
def m3()
|
86
|
-
puts "m3"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Test for multiline string
|
91
|
-
def m (x)
|
92
|
-
puts "This is multi-line string. It's line1 \
|
93
|
-
It's line 2\
|
94
|
-
And this is\n line3
|
95
|
-
This line should not be mutated"
|
96
|
-
puts "This is multi line interpolated string #{
|
97
|
-
x
|
98
|
-
}"
|
99
|
-
end
|
100
|
-
|
101
|
-
# Test to validate case statements
|
102
|
-
def case_test opts=nil
|
103
|
-
case test_case
|
104
|
-
when 'Passing'
|
105
|
-
call(:pass)
|
106
|
-
when 'Failing'
|
107
|
-
call(:fail)
|
108
|
-
when 'Error'
|
109
|
-
call(:error)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Test for variable assignment from an if statement
|
114
|
-
@products = if params[:category]
|
115
|
-
Category.find(params[:category]).products
|
116
|
-
else
|
117
|
-
Product.all
|
118
|
-
end
|
119
|
-
|
120
|
-
# Test for variable assignment from a block
|
121
|
-
response = begin
|
122
|
-
if true?
|
123
|
-
api_call(test)
|
124
|
-
else
|
125
|
-
rejected
|
126
|
-
end
|
127
|
-
rescue
|
128
|
-
'FALSE'
|
129
|
-
end
|
130
|
-
|
131
|
-
# Test or-equals
|
132
|
-
def expensive_value
|
133
|
-
@expensive_value ||= begin
|
134
|
-
if conn.active?
|
135
|
-
expensive_call
|
136
|
-
else
|
137
|
-
:none
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# Test multiple or-equals
|
143
|
-
def expensive_value
|
144
|
-
@expensive_value ||= @cached_value ||= begin
|
145
|
-
if conn.active?
|
146
|
-
expensive_call
|
147
|
-
else
|
148
|
-
:none
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
data/spec/example_beautified.rb
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'ripper'
|
2
|
-
|
3
|
-
module Here
|
4
|
-
class There
|
5
|
-
def why?(argument = nil)
|
6
|
-
@array = [
|
7
|
-
1,
|
8
|
-
2,
|
9
|
-
3
|
10
|
-
]
|
11
|
-
hash = {
|
12
|
-
one:1,
|
13
|
-
two:2,
|
14
|
-
three:3
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
# a comment
|
19
|
-
def why_not?(argument: {})
|
20
|
-
@array = [4,5,6]
|
21
|
-
hash = {four:4, five:5, six:6}
|
22
|
-
s = "a #{"complex"} string."
|
23
|
-
end
|
24
|
-
|
25
|
-
def complex_method(one, two, three, four)
|
26
|
-
regex = /regex/
|
27
|
-
end
|
28
|
-
|
29
|
-
def with_block
|
30
|
-
run = Proc.new { |argument| puts arugment }
|
31
|
-
run do |arugment|
|
32
|
-
puts argument
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
h = Here::There.new
|
39
|
-
|
40
|
-
h.why?({
|
41
|
-
here: 'there',
|
42
|
-
there: 'here'
|
43
|
-
})
|
44
|
-
|
45
|
-
h.with_block {
|
46
|
-
puts 'yahooie'
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
51
|
-
'alfkjsdlkfjsflgkjfglk',
|
52
|
-
'alfkjsdlkfjsflgkjfglk',
|
53
|
-
'alfkjsdlkfjsflgkjfglk'
|
54
|
-
)
|
55
|
-
|
56
|
-
h.complex_method('asdkjasflkjdglksjglksfgjlfkgjdf',
|
57
|
-
'alfkjsdlkfjsflgkjfglk',
|
58
|
-
'alfkjsdlkfjsflgkjfglk',
|
59
|
-
'alfkjsdlkfjsflgkjfglk'
|
60
|
-
).map do |i|
|
61
|
-
i
|
62
|
-
end.map! { |i| i }
|
63
|
-
|
64
|
-
if 1 > 0
|
65
|
-
puts 'something'
|
66
|
-
elsif 1 < 0
|
67
|
-
puts 'never!'
|
68
|
-
else
|
69
|
-
puts 'not likely.'
|
70
|
-
end
|
71
|
-
|
72
|
-
#Test for different if-statement formatting
|
73
|
-
if 1 > 0 then puts 'something'
|
74
|
-
else puts 'nothing' end
|
75
|
-
puts "This line should stay the same"
|
76
|
-
|
77
|
-
# Test for already indented blocks
|
78
|
-
class There2 < There
|
79
|
-
def m1()
|
80
|
-
puts "m1"
|
81
|
-
end
|
82
|
-
def m2()
|
83
|
-
puts "m2"
|
84
|
-
end
|
85
|
-
def m3()
|
86
|
-
puts "m3"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
# Test for multiline string
|
91
|
-
def m (x)
|
92
|
-
puts "This is multi-line string. It's line1 \
|
93
|
-
It's line 2\
|
94
|
-
And this is\n line3
|
95
|
-
This line should not be mutated"
|
96
|
-
puts "This is multi line interpolated string #{
|
97
|
-
x
|
98
|
-
}"
|
99
|
-
end
|
100
|
-
|
101
|
-
# Test to validate case statements
|
102
|
-
def case_test opts=nil
|
103
|
-
case test_case
|
104
|
-
when 'Passing'
|
105
|
-
call(:pass)
|
106
|
-
when 'Failing'
|
107
|
-
call(:fail)
|
108
|
-
when 'Error'
|
109
|
-
call(:error)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# Test for variable assignment from an if statement
|
114
|
-
@products = if params[:category]
|
115
|
-
Category.find(params[:category]).products
|
116
|
-
else
|
117
|
-
Product.all
|
118
|
-
end
|
119
|
-
|
120
|
-
# Test for variable assignment from a block
|
121
|
-
response = begin
|
122
|
-
if true?
|
123
|
-
api_call(test)
|
124
|
-
else
|
125
|
-
rejected
|
126
|
-
end
|
127
|
-
rescue
|
128
|
-
'FALSE'
|
129
|
-
end
|
130
|
-
|
131
|
-
# Test or-equals
|
132
|
-
def expensive_value
|
133
|
-
@expensive_value ||= begin
|
134
|
-
if conn.active?
|
135
|
-
expensive_call
|
136
|
-
else
|
137
|
-
:none
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# Test multiple or-equals
|
143
|
-
def expensive_value
|
144
|
-
@expensive_value ||= @cached_value ||= begin
|
145
|
-
if conn.active?
|
146
|
-
expensive_call
|
147
|
-
else
|
148
|
-
:none
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|