syntax_fix 0.0.3 → 0.0.4
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 +7 -0
- data/bin/syntax_fix +1 -1
- data/lib/syntax_fix/checker.rb +9 -4
- data/lib/syntax_fix/dir_file.rb +6 -2
- data/lib/syntax_fix/version.rb +1 -1
- data/spec/specs/checker_spec.rb +16 -2
- data/spec/specs/dir_file_spec.rb +6 -1
- metadata +10 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 59d5dd7104017a29af3ab763beb47c081897fb29
|
4
|
+
data.tar.gz: 81f9844491b9b8dca4b97b1e61df405f317673eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e39e22129e9bd062b1cca54e780453f45311d1ceb5b23e7e4dd915735634efd0fbe984fb5224b8f85b3bc06b1401baaec3b6e93f79cf29f603998903fd1172b
|
7
|
+
data.tar.gz: 1c36cfe34be8aa032b89c834b0d6fb80ec8f8447b181eeb5599c04e51ee218d8adae9d625b3b327dbf8c0ddeb74cdd5aa83830da36fb03c245d9064122371050
|
data/bin/syntax_fix
CHANGED
@@ -11,7 +11,7 @@ optparse = OptionParser.new do |opts|
|
|
11
11
|
opts.on( '-v', '--verbose', 'Be verbose about the actions' ) do
|
12
12
|
checker.verbose = true
|
13
13
|
end
|
14
|
-
opts.on( '-p [PATH]', '--path [PATH]', 'Specify the relative path
|
14
|
+
opts.on( '-p [PATH or FILENAME]', '--path [PATH or FILENAME]', 'Specify the relative path to start actions from or a single file' ) do |path|
|
15
15
|
checker.rel_path = path
|
16
16
|
end
|
17
17
|
checker.rel_path ||= '.'
|
data/lib/syntax_fix/checker.rb
CHANGED
@@ -3,9 +3,14 @@ module SyntaxFix
|
|
3
3
|
attr_accessor :verbose, :rel_path
|
4
4
|
|
5
5
|
def fix_code(path)
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
dirfile = SyntaxFix::DirFile.new(path)
|
7
|
+
if dirfile.is_dir?
|
8
|
+
Dir.foreach(path) do |name|
|
9
|
+
current_item = SyntaxFix::DirFile.new([path, name].join('/'))
|
10
|
+
current_item.is_dir? ? fix_code(current_item.path) : fix_file(current_item)
|
11
|
+
end
|
12
|
+
elsif dirfile.is_file?
|
13
|
+
fix_file dirfile
|
9
14
|
end
|
10
15
|
end
|
11
16
|
|
@@ -24,4 +29,4 @@ module SyntaxFix
|
|
24
29
|
source.gsub(/([^\:])\:([a-zA-Z_0-9]*)(\s*)=\>(\s*)/){|match| "#{$1}#{$2}:#{$3.empty? || ($3+$4).empty? ? " " : $3}"}
|
25
30
|
end
|
26
31
|
end
|
27
|
-
end
|
32
|
+
end
|
data/lib/syntax_fix/dir_file.rb
CHANGED
@@ -5,13 +5,17 @@ module SyntaxFix
|
|
5
5
|
|
6
6
|
def initialize(path)
|
7
7
|
@path = path
|
8
|
-
@check_exts = ['rb', 'erb', 'rake']
|
8
|
+
@check_exts = ['rb', 'erb', 'rake', 'haml', 'slim']
|
9
9
|
end
|
10
10
|
|
11
11
|
def is_dir?
|
12
12
|
File.directory?(@path) && !['.', '..'].include?(File.basename(@path))
|
13
13
|
end
|
14
14
|
|
15
|
+
def is_file?
|
16
|
+
File.file?(@path) && !['.', '..'].include?(File.basename(@path))
|
17
|
+
end
|
18
|
+
|
15
19
|
def correct_file?
|
16
20
|
File.file?(@path) && File.writable?(@path) && check_exts.include?(File.extname(@path)[1..-1])
|
17
21
|
end
|
@@ -24,4 +28,4 @@ module SyntaxFix
|
|
24
28
|
File.open(@path, 'r') {|f| f.read}
|
25
29
|
end
|
26
30
|
end
|
27
|
-
end
|
31
|
+
end
|
data/lib/syntax_fix/version.rb
CHANGED
data/spec/specs/checker_spec.rb
CHANGED
@@ -5,11 +5,25 @@ describe SyntaxFix::Checker do
|
|
5
5
|
@path = "#{File.expand_path('.')}/spec/fixtures"
|
6
6
|
end
|
7
7
|
|
8
|
-
it "fixes hash syntax" do
|
8
|
+
it "fixes hash syntax when a directory is passed as path argument" do
|
9
9
|
fixed_content = File.open("#{@path}/test/fixed_test.txt") {|f| f.read}
|
10
10
|
checker = SyntaxFix::Checker.new
|
11
11
|
SyntaxFix::DirFile.any_instance.should_receive(:write_file).with(fixed_content)
|
12
12
|
checker.fix_code("#{@path}/test")
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
it "fixes hash syntax when a file is passed as path argument" do
|
16
|
+
fixed_content = File.open("#{@path}/test/fixed_test.txt") {|f| f.read}
|
17
|
+
checker = SyntaxFix::Checker.new
|
18
|
+
SyntaxFix::DirFile.any_instance.should_receive(:write_file).with(fixed_content)
|
19
|
+
checker.fix_code("#{@path}/test.rb")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "does nothing when a wrong filename is passed as path argument" do
|
23
|
+
fixed_content = File.open("#{@path}/test/fixed_test.txt") {|f| f.read}
|
24
|
+
checker = SyntaxFix::Checker.new
|
25
|
+
SyntaxFix::DirFile.any_instance.should_not_receive(:write_file).with(fixed_content)
|
26
|
+
checker.fix_code("#{@path}/wrong.rb")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/specs/dir_file_spec.rb
CHANGED
@@ -10,6 +10,11 @@ describe SyntaxFix::DirFile do
|
|
10
10
|
dir.is_dir?.should be_true
|
11
11
|
end
|
12
12
|
|
13
|
+
it "checks if current item is a file" do
|
14
|
+
file = SyntaxFix::DirFile.new("#{@path}/test.rb")
|
15
|
+
file.is_file?.should be_true
|
16
|
+
end
|
17
|
+
|
13
18
|
it "returns false when dir is '..'" do
|
14
19
|
dir = SyntaxFix::DirFile.new("#{@path}/nested/.")
|
15
20
|
dir.is_dir?.should be_false
|
@@ -38,4 +43,4 @@ describe SyntaxFix::DirFile do
|
|
38
43
|
file.read_file.should == 'not_rb.txt'
|
39
44
|
end
|
40
45
|
|
41
|
-
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_fix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Sergey Parizhskiy
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-11-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: Replace Ruby 1.8 syntax with the Ruby 1.9 syntax all over the project
|
@@ -58,26 +55,26 @@ files:
|
|
58
55
|
- syntax_fix.gemspec
|
59
56
|
homepage: https://github.com/HeeL/syntax_fix
|
60
57
|
licenses: []
|
58
|
+
metadata: {}
|
61
59
|
post_install_message:
|
62
60
|
rdoc_options: []
|
63
61
|
require_paths:
|
64
62
|
- lib
|
65
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
64
|
requirements:
|
68
|
-
- -
|
65
|
+
- - '>='
|
69
66
|
- !ruby/object:Gem::Version
|
70
67
|
version: '0'
|
71
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
69
|
requirements:
|
74
|
-
- -
|
70
|
+
- - '>='
|
75
71
|
- !ruby/object:Gem::Version
|
76
72
|
version: '0'
|
77
73
|
requirements: []
|
78
74
|
rubyforge_project: syntax_fix
|
79
|
-
rubygems_version:
|
75
|
+
rubygems_version: 2.0.3
|
80
76
|
signing_key:
|
81
|
-
specification_version:
|
77
|
+
specification_version: 4
|
82
78
|
summary: Replace Ruby 1.8 syntax with the modern one
|
83
79
|
test_files: []
|
80
|
+
has_rdoc:
|