Class: Codeshift::Transformer
- Inherits:
-
Object
- Object
- Codeshift::Transformer
- Defined in:
- lib/codeshift/transformer.rb
Overview
Transformer Class
Instance Method Summary collapse
-
#initialize(code, transform) ⇒ Transformer
constructor
A new instance of Transformer.
- #transform ⇒ Object
Constructor Details
#initialize(code, transform) ⇒ Transformer
Returns a new instance of Transformer.
8 9 10 11 |
# File 'lib/codeshift/transformer.rb', line 8 def initialize(code, transform) @code = code @transform = transform end |
Instance Method Details
#transform ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/codeshift/transformer.rb', line 13 def transform eval(@transform) buffer = Parser::Source::Buffer.new('(example)') buffer.source = @code begin temp = Parser::CurrentRuby.parse(@code) rewriter = Transform.new # Rewrite the AST, returns a String with the new form. output = rewriter.rewrite(buffer, temp) rescue puts 'Unknown parsing error' @code end end |