Class: Synvert::CheckingVisitor
- Inherits:
-
Object
- Object
- Synvert::CheckingVisitor
- Defined in:
- lib/synvert/checking_visitor.rb
Instance Attribute Summary collapse
-
#converters ⇒ Object
readonly
Returns the value of attribute converters.
Instance Method Summary collapse
- #convert(filename, source) ⇒ Object
- #convert_file(filename) ⇒ Object
-
#initialize(options = {}) ⇒ CheckingVisitor
constructor
A new instance of CheckingVisitor.
Constructor Details
#initialize(options = {}) ⇒ CheckingVisitor
Returns a new instance of CheckingVisitor.
6 7 8 9 10 |
# File 'lib/synvert/checking_visitor.rb', line 6 def initialize(={}) @converters = [:converters] || [ Synvert::FactoryGirl::SyntaxMethodsConverter.new ] end |
Instance Attribute Details
#converters ⇒ Object (readonly)
Returns the value of attribute converters.
4 5 6 |
# File 'lib/synvert/checking_visitor.rb', line 4 def converters @converters end |
Instance Method Details
#convert(filename, source) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/synvert/checking_visitor.rb', line 20 def convert(filename, source) source_buffer = Parser::Source::Buffer.new filename source_buffer.source = source parser = Parser::CurrentRuby.new ast = parser.parse source_buffer converted_source = source @converters.each do |converter| if Array(converter.interesting_files).any? { |file_pattern| filename =~ file_pattern } converted_source = converter.rewrite(source_buffer, ast) end end converted_source end |
#convert_file(filename) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/synvert/checking_visitor.rb', line 12 def convert_file(filename) source = File.read filename converted_source = convert(filename, source) if source != converted_source File.write(filename, converted_source) end end |