Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 8 additions and 1 deletion.
  1. +1 −1  bin/magic_encoding
  2. +7 −0 lib/magic_encoding.rb
View
2  bin/magic_encoding 100644 → 100755
@@ -2,6 +2,6 @@
# A simple tool to prepend magic comments for encoding to multiple ".rb" files
-require 'magic_encoding'
+require File.join(File.dirname(__FILE__), *%w[.. lib magic_encoding])
AddMagicComment.process(ARGV)
View
7 lib/magic_encoding.rb
@@ -2,6 +2,7 @@
# A simple library to prepend magic comments for encoding to multiple ".rb" files
+require 'open3'
module AddMagicComment
# Options :
@@ -29,6 +30,7 @@ def self.process(options)
extensions.each do |ext, comment_style|
rbfiles = File.join(directory ,'**', '*.'+ext)
Dir.glob(rbfiles).each do |filename|
+ next if syntax_ok?(filename)
file = File.new(filename, "r+")
lines = file.readlines
@@ -54,6 +56,11 @@ def self.process(options)
puts "Magic comments set for #{count} source files"
end
+ def self.syntax_ok?(filename)
+ stdin, stdout, stderr = Open3.popen3("ruby -c #{filename}")
+ stdout.read.include?("Syntax OK")
+ end
+
end
class String

No commit comments for this range

Something went wrong with that request. Please try again.