Sha256: bd802e55b90bc3f1e91ad288cff55755565fd1fe155cf15fa756ae2800d29c7b
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
# encoding: utf-8 module Synvert class Rewriter::Action def initialize(code) @code = code end def rewrite(source, node) raise NotImplementedError.new 'rewrite method is not implemented' end end class Rewriter::ReplaceWithAction < Rewriter::Action def rewrite(source, node) begin_pos = node.loc.expression.begin_pos end_pos = node.loc.expression.end_pos source[begin_pos...end_pos] = node.to_source(@code) source end end class Rewriter::InsertAction < Rewriter::Action def rewrite(source, node) source[insert_position(node), 0] = "\n" + insert_indent(node) + node.to_source(@code) source end def insert_position(node) case node.type when :block node.children[1].loc.expression.end_pos when :class node.children[0].loc.expression.end_pos else node.children.last.loc.expression.end_pos end end def insert_indent(node) if [:block, :class].include? node.type ' ' * (node.indent + 2) else ' ' * node.indent end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
synvert-0.0.2 | lib/synvert/rewriter/action.rb |