Class: Magic::Commenter
- Inherits:
-
Object
- Object
- Magic::Commenter
- Includes:
- Open3
- Defined in:
- lib/magic-commenter.rb,
lib/magic-commenter/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #add_magic_comment(file) ⇒ Object
-
#initialize(files) ⇒ Commenter
constructor
A new instance of Commenter.
Constructor Details
#initialize(files) ⇒ Commenter
Returns a new instance of Commenter.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/magic-commenter.rb', line 10 def initialize(files) for file in files errors = [] popen3("ruby -c #{file}") do |stdin, stdout, stderr| errors = stderr.read.split("\n") end if errors.any?{|error| error.include?("invalid multibyte char")} puts ">> Fixing #{file}" add_magic_comment(file) end end end |
Instance Method Details
#add_magic_comment(file) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/magic-commenter.rb', line 24 def add_magic_comment(file) contents = "# -*- encoding: utf-8 -*-\n" + File.read(file) File.open(file,"w") do |f| f.write contents f.close end end |