syntax_fix 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format doc
@@ -0,0 +1,4 @@
1
+ v0.0.1
2
+ ======
3
+
4
+ * change the hash syntax from Ruby 1.8 to Ruby 1.9 style
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in syntax_fix.gemspec
4
+ gemspec
@@ -0,0 +1,34 @@
1
+ Description
2
+ ===========
3
+
4
+ syntax_fix gem goes through all files and directories and change the old Ruby 1.8 syntax to a new one.
5
+
6
+ Features
7
+ ========
8
+
9
+ What we've got so far:
10
+
11
+ * change hash style from ':key => "value"' to 'key: "value"'
12
+
13
+ Install
14
+ =======
15
+
16
+ `gem install syntax_fix`
17
+
18
+ OR
19
+
20
+ Put this line in your Gemfile:
21
+ `gem 'syntax_fix'`
22
+
23
+ Then bundle:
24
+ `$ bundle`
25
+
26
+ Usage
27
+ =======
28
+
29
+ `syntax_fix` command will check and rewrite all files with the new syntax (including nested files and directories)
30
+
31
+ Contributing
32
+ ============
33
+
34
+ If you consider to contribute to syntax_fix gem, please try to cover your code with tests
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'syntax_fix'
3
+
4
+ checker = SyntaxFix::Checker.new
5
+ checker.fix_code(File.expand_path('.'))
@@ -0,0 +1,5 @@
1
+ $:.push File.expand_path(File.dirname(__FILE__))
2
+ require "syntax_fix/version"
3
+
4
+ SyntaxFix.autoload :Checker, 'syntax_fix/checker.rb'
5
+ SyntaxFix.autoload :DirFile, 'syntax_fix/dir_file.rb'
@@ -0,0 +1,22 @@
1
+ module SyntaxFix
2
+ class Checker
3
+ def fix_code(path)
4
+ Dir.foreach(path) do |name|
5
+ current_item = SyntaxFix::DirFile.new([path, name].join('/'))
6
+ current_item.is_dir? ? fix_code(current_item.path) : fix_file(current_item)
7
+ end
8
+ end
9
+
10
+ private
11
+ def fix_file(current_item)
12
+ return if !current_item.correct_file?
13
+ content = current_item.read_file
14
+ fixed_content = fix_syntax(content)
15
+ current_item.write_file(fixed_content) if content != fixed_content
16
+ end
17
+
18
+ def fix_syntax(source)
19
+ source.gsub(/\:([a-zA-Z_0-9]*)(\s*)=\>(\s*)/){|match| "#{$1}:#{$2.empty? || ($2+$3).empty? ? " " : $2}"}
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module SyntaxFix
2
+ class DirFile
3
+ attr_accessor :check_exts
4
+ attr_reader :path
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ @check_exts = ['rb', 'erb', 'rake']
9
+ end
10
+
11
+ def is_dir?
12
+ File.directory?(@path) && !['.', '..'].include?(File.basename(@path))
13
+ end
14
+
15
+ def correct_file?
16
+ File.file?(@path) && File.writable?(@path) && check_exts.include?(File.extname(@path)[1..-1])
17
+ end
18
+
19
+ def write_file(source)
20
+ File.open(@path, 'w') {|f| f.write(source)}
21
+ end
22
+
23
+ def read_file
24
+ File.open(@path, 'r') {|f| f.read}
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module SyntaxFix
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ nested.rb
@@ -0,0 +1 @@
1
+ not_rb.txt
@@ -0,0 +1 @@
1
+ not_rb.dat
@@ -0,0 +1,9 @@
1
+ test_str = 'some ruby code goes here'
2
+
3
+ test_hash = {:test => 'test', :no_space=>0, :many_spaces => 1}
4
+
5
+ test_hash2 =
6
+ {
7
+ :key => 'value',
8
+ :test_123 => 123
9
+ }
@@ -0,0 +1,9 @@
1
+ test_str = 'some ruby code goes here'
2
+
3
+ test_hash = {test: 'test', no_space: 0, many_spaces: 1}
4
+
5
+ test_hash2 =
6
+ {
7
+ key: 'value',
8
+ test_123: 123
9
+ }
@@ -0,0 +1,9 @@
1
+ test_str = 'some ruby code goes here'
2
+
3
+ test_hash = {:test => 'test', :no_space=>0, :many_spaces => 1}
4
+
5
+ test_hash2 =
6
+ {
7
+ :key => 'value',
8
+ :test_123 => 123
9
+ }
@@ -0,0 +1,3 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require 'syntax_fix.rb'
@@ -0,0 +1,15 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe SyntaxFix::Checker do
4
+ before(:each) do
5
+ @path = "#{File.expand_path('.')}/spec/fixtures"
6
+ end
7
+
8
+ it "fixes hash syntax" do
9
+ fixed_content = File.open("#{@path}/test/fixed_test.txt") {|f| f.read}
10
+ checker = SyntaxFix::Checker.new
11
+ SyntaxFix::DirFile.any_instance.should_receive(:write_file).with(fixed_content)
12
+ checker.fix_code("#{@path}/test")
13
+ end
14
+
15
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe SyntaxFix::DirFile do
4
+ before(:all) do
5
+ @path = "#{File.expand_path('.')}/spec/fixtures"
6
+ end
7
+
8
+ it "checks if current item is a dir" do
9
+ dir = SyntaxFix::DirFile.new("#{@path}/nested")
10
+ dir.is_dir?.should be_true
11
+ end
12
+
13
+ it "returns false when dir is '..'" do
14
+ dir = SyntaxFix::DirFile.new("#{@path}/nested/.")
15
+ dir.is_dir?.should be_false
16
+ end
17
+
18
+ it "doesn't read files with dat extension" do
19
+ not_correct = SyntaxFix::DirFile.new("#{@path}/not_rb.dat")
20
+ not_correct.correct_file?.should be_false
21
+ end
22
+
23
+ it "reads files with rb extension" do
24
+ correct = SyntaxFix::DirFile.new("#{@path}/test.rb")
25
+ correct.correct_file?.should be_true
26
+ end
27
+
28
+ it "reads the given file" do
29
+ dir = SyntaxFix::DirFile.new("#{@path}/nested/nested.rb")
30
+ dir.read_file.should == 'nested.rb'
31
+ end
32
+
33
+ it "puts given source into a file" do
34
+ path = "#{@path}/nested/not_rb.txt"
35
+ File.truncate(path, 0)
36
+ file = SyntaxFix::DirFile.new(path)
37
+ file.write_file('not_rb.txt')
38
+ file.read_file.should == 'not_rb.txt'
39
+ end
40
+
41
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "syntax_fix/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "syntax_fix"
7
+ s.version = SyntaxFix::VERSION
8
+ s.authors = ["Sergey Parizhskiy"]
9
+ s.email = ["parizhskiy@gmail.com"]
10
+ s.homepage = "https://github.com/HeeL/syntax_fix"
11
+ s.summary = %q{Replace Ruby 1.8 syntax with the modern one}
12
+ s.description = %q{Replace Ruby 1.8 syntax with the Ruby 1.9 syntax all over the project}
13
+
14
+ s.rubyforge_project = "syntax_fix"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syntax_fix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sergey Parizhskiy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2151905220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2151905220
25
+ description: Replace Ruby 1.8 syntax with the Ruby 1.9 syntax all over the project
26
+ email:
27
+ - parizhskiy@gmail.com
28
+ executables:
29
+ - syntax_fix
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - .rspec
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - bin/syntax_fix
40
+ - lib/syntax_fix.rb
41
+ - lib/syntax_fix/checker.rb
42
+ - lib/syntax_fix/dir_file.rb
43
+ - lib/syntax_fix/version.rb
44
+ - spec/fixtures/nested/nested.rb
45
+ - spec/fixtures/nested/not_rb.txt
46
+ - spec/fixtures/not_rb.dat
47
+ - spec/fixtures/test.rb
48
+ - spec/fixtures/test/fixed_test.txt
49
+ - spec/fixtures/test/test.rb
50
+ - spec/spec_helper.rb
51
+ - spec/specs/checker_spec.rb
52
+ - spec/specs/dir_file_spec.rb
53
+ - syntax_fix.gemspec
54
+ homepage: https://github.com/HeeL/syntax_fix
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project: syntax_fix
74
+ rubygems_version: 1.8.10
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Replace Ruby 1.8 syntax with the modern one
78
+ test_files:
79
+ - spec/fixtures/nested/nested.rb
80
+ - spec/fixtures/nested/not_rb.txt
81
+ - spec/fixtures/not_rb.dat
82
+ - spec/fixtures/test.rb
83
+ - spec/fixtures/test/fixed_test.txt
84
+ - spec/fixtures/test/test.rb
85
+ - spec/spec_helper.rb
86
+ - spec/specs/checker_spec.rb
87
+ - spec/specs/dir_file_spec.rb