syntax_fix 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ v0.0.2
2
+ ======
3
+
4
+ * added ability to pass arguments from a command line. --verbose and --help
5
+
1
6
  v0.0.1
2
7
  ======
3
8
 
data/README.md CHANGED
@@ -28,6 +28,10 @@ Usage
28
28
 
29
29
  `syntax_fix` command will check and rewrite all files with the new syntax (including nested files and directories)
30
30
 
31
+ `-h` or `--help` - output all the possible arguments that you can pass from a command line
32
+
33
+ `-v` or `--verbose` - be verbose about the actions
34
+
31
35
  Contributing
32
36
  ============
33
37
 
@@ -1,5 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'syntax_fix'
3
+ require 'optparse'
3
4
 
4
5
  checker = SyntaxFix::Checker.new
6
+ optparse = OptionParser.new do |opts|
7
+ opts.on( '-h', '--help', 'Display this screen' ) do
8
+ puts opts
9
+ exit
10
+ end
11
+ opts.on( '-v', '--verbose', 'Be verbose about the actions' ) do
12
+ checker.verbose = true
13
+ end
14
+ end
15
+ optparse.parse!
16
+
17
+ puts 'Reading files...' if checker.verbose
5
18
  checker.fix_code(File.expand_path('.'))
19
+ puts 'Done!' if checker.verbose
@@ -1,5 +1,7 @@
1
1
  module SyntaxFix
2
2
  class Checker
3
+ attr_accessor :verbose
4
+
3
5
  def fix_code(path)
4
6
  Dir.foreach(path) do |name|
5
7
  current_item = SyntaxFix::DirFile.new([path, name].join('/'))
@@ -12,11 +14,14 @@ module SyntaxFix
12
14
  return if !current_item.correct_file?
13
15
  content = current_item.read_file
14
16
  fixed_content = fix_syntax(content)
15
- current_item.write_file(fixed_content) if content != fixed_content
17
+ if content != fixed_content
18
+ current_item.write_file(fixed_content)
19
+ puts "#{current_item.path} [CHANGED]" if verbose
20
+ end
16
21
  end
17
22
 
18
23
  def fix_syntax(source)
19
- source.gsub(/\:([a-zA-Z_0-9]*)(\s*)=\>(\s*)/){|match| "#{$1}:#{$2.empty? || ($2+$3).empty? ? " " : $2}"}
24
+ source.gsub(/([^\:])\:([a-zA-Z_0-9]*)(\s*)=\>(\s*)/){|match| "#{$1}#{$2}:#{$3.empty? || ($3+$4).empty? ? " " : $3}"}
20
25
  end
21
26
  end
22
27
  end
@@ -1,3 +1,3 @@
1
1
  module SyntaxFix
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_fix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-27 00:00:00.000000000 Z
12
+ date: 2012-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2151905220 !ruby/object:Gem::Requirement
16
+ requirement: &70094412006620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2151905220
24
+ version_requirements: *70094412006620
25
25
  description: Replace Ruby 1.8 syntax with the Ruby 1.9 syntax all over the project
26
26
  email:
27
27
  - parizhskiy@gmail.com
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  requirements: []
73
73
  rubyforge_project: syntax_fix
74
- rubygems_version: 1.8.10
74
+ rubygems_version: 1.8.11
75
75
  signing_key:
76
76
  specification_version: 3
77
77
  summary: Replace Ruby 1.8 syntax with the modern one