ruby-beautify 0.94.1 → 0.94.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0d8f2666a10cd5f951233487ef5bcbc18226747
4
- data.tar.gz: a43bca59db59c2aa94b1ea8538c7aa29ba0a19f8
3
+ metadata.gz: 0200f47ad7a7b3b4db0cc305cc01c58e5f33e06f
4
+ data.tar.gz: bbc3bb4107a01d04cecfefb3437388749cd7cf8c
5
5
  SHA512:
6
- metadata.gz: 87e379a981c675498389680e58e60cc398d3709c2572bd4eef4cd39120a41679bb992663c86dae23ad02f2c06d0c3fcdba6fc28cfe7a115069f46c3356bc6a3a
7
- data.tar.gz: 5a6dbf3aa9c9f2ab1e92e6d7c00006f0e92bc598093512d4e4d36ec882b464cebe4b776d2abd4854f24d5eca2463a36d7a31e0a217d9085cae05e532591cd562
6
+ metadata.gz: 159b269436d56dce50cd217743b5423f7b6206a5ae64368b0a0aa60461f58fb8d95f030447c75787bac7eadab920c86801765561ef131485fdcc1cdaf3360f9c
7
+ data.tar.gz: 3c03b30b349a34338caf00e6686eafe3f13ec49e30e18737c57daa058c20a55683c07688daebdfd9ae1404c4b757093f706fbcac062ca105398a8e677ef6c120
data/README.md CHANGED
@@ -56,6 +56,9 @@ Please feel free to open issues, I am actively working on this project again, th
56
56
  * Add overwrite in place to files.
57
57
  * Add 'best guest' for files that fail syntax checking.
58
58
  * Add syntax checking to files rendered via STDIN.
59
+ * Seperate the content of the main bin into a proper namespace/library (so it doesn't pollute by default).
60
+ * Split up the spec into multiple specs.
61
+ * remove the link to rbeautify (by 1.0).
59
62
 
60
63
  Longer term I'd like to do some more to assignment, line wrapping, and spacing in/around keywords.
61
64
 
data/WHATSNEW.md CHANGED
@@ -1,4 +1,8 @@
1
- ## 0.94.1
1
+ ## 0.94.2
2
+ * Support for case statements thanks to @pkuykendall.
3
+ * @pkuykendall also brings us proper syntax formatting for assignments from the return value of an if check (that's a mouth full).
4
+
5
+ ## 0.94.1
2
6
  * Multiline string and embedded doc support thanks to @veelenga.
3
7
 
4
8
  ## 0.94.0
data/bin/rbeautify CHANGED
@@ -12,8 +12,8 @@ Options = OptionParser.new do |opts|
12
12
  end
13
13
  Options.parse!
14
14
 
15
- @open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless']
16
- @both_block = ["else", "elsif", 'rescue']
15
+ @open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless', 'case']
16
+ @both_block = ["else", "elsif", 'rescue', 'when']
17
17
  @open_block_do = ['do', '{']
18
18
  @close_block = ['end', '}']
19
19
 
@@ -81,6 +81,7 @@ end
81
81
 
82
82
  # is the first word a key word?
83
83
  def starts_block?(line_lex)
84
+ return true if contains_block_assignment? line_lex
84
85
  line_lex.each do |x|
85
86
  # search for a first non-space token
86
87
  if not x[1] == :on_sp
@@ -147,6 +148,16 @@ def closing_assignment?(line_lex)
147
148
  return true if closes > opens
148
149
  end
149
150
 
151
+ # test for assignment from a block
152
+ def contains_block_assignment?(line_lex)
153
+ compacted_line = line_lex.reject{|x| x[1] == :on_sp} #remove spaces
154
+ idx = compacted_line.find_index{|x| x[2] == '='} #find first equal sign
155
+ if idx
156
+ return @open_block_start.include?(compacted_line[idx+1][2]) #check for if/begin block
157
+ end
158
+ return false
159
+ end
160
+
150
161
  # is this ruby file valid syntax?
151
162
  def valid_syntax?(file)
152
163
  #ugly but fast, ruby returns stdout if it's ok, and stderr if not.
data/bin/ruby-beautify CHANGED
@@ -12,8 +12,8 @@ Options = OptionParser.new do |opts|
12
12
  end
13
13
  Options.parse!
14
14
 
15
- @open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless']
16
- @both_block = ["else", "elsif", 'rescue']
15
+ @open_block_start = ["module", "class", "begin", "def", 'if', 'while', 'unless', 'case']
16
+ @both_block = ["else", "elsif", 'rescue', 'when']
17
17
  @open_block_do = ['do', '{']
18
18
  @close_block = ['end', '}']
19
19
 
@@ -81,6 +81,7 @@ end
81
81
 
82
82
  # is the first word a key word?
83
83
  def starts_block?(line_lex)
84
+ return true if contains_block_assignment? line_lex
84
85
  line_lex.each do |x|
85
86
  # search for a first non-space token
86
87
  if not x[1] == :on_sp
@@ -147,6 +148,16 @@ def closing_assignment?(line_lex)
147
148
  return true if closes > opens
148
149
  end
149
150
 
151
+ # test for assignment from a block
152
+ def contains_block_assignment?(line_lex)
153
+ compacted_line = line_lex.reject{|x| x[1] == :on_sp} #remove spaces
154
+ idx = compacted_line.find_index{|x| x[2] == '='} #find first equal sign
155
+ if idx
156
+ return @open_block_start.include?(compacted_line[idx+1][2]) #check for if/begin block
157
+ end
158
+ return false
159
+ end
160
+
150
161
  # is this ruby file valid syntax?
151
162
  def valid_syntax?(file)
152
163
  #ugly but fast, ruby returns stdout if it's ok, and stderr if not.
@@ -1,3 +1,3 @@
1
1
  module RBeautify
2
- VERSION = "0.94.1"
2
+ VERSION = "0.94.2"
3
3
  end
data/spec/example.rb CHANGED
@@ -92,3 +92,33 @@ puts "This is multi line interpolated string #{
92
92
  x
93
93
  }"
94
94
  end
95
+
96
+ # Test to validate case statements
97
+ def case_test opts=nil
98
+ case test_case
99
+ when 'Passing'
100
+ call(:pass)
101
+ when 'Failing'
102
+ call(:fail)
103
+ when 'Error'
104
+ call(:error)
105
+ end
106
+ end
107
+
108
+ # Test for variable assignment from an if statement
109
+ @products = if params[:category]
110
+ Category.find(params[:category]).products
111
+ else
112
+ Product.all
113
+ end
114
+
115
+ # Test for variable assignment from a block
116
+ response = begin
117
+ if true?
118
+ api_call(test)
119
+ else
120
+ rejected
121
+ end
122
+ rescue
123
+ 'FALSE'
124
+ end
@@ -92,3 +92,33 @@ def m (x)
92
92
  x
93
93
  }"
94
94
  end
95
+
96
+ # Test to validate case statements
97
+ def case_test opts=nil
98
+ case test_case
99
+ when 'Passing'
100
+ call(:pass)
101
+ when 'Failing'
102
+ call(:fail)
103
+ when 'Error'
104
+ call(:error)
105
+ end
106
+ end
107
+
108
+ # Test for variable assignment from an if statement
109
+ @products = if params[:category]
110
+ Category.find(params[:category]).products
111
+ else
112
+ Product.all
113
+ end
114
+
115
+ # Test for variable assignment from a block
116
+ response = begin
117
+ if true?
118
+ api_call(test)
119
+ else
120
+ rejected
121
+ end
122
+ rescue
123
+ 'FALSE'
124
+ 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.94.1
4
+ version: 0.94.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Brodeur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-23 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake