Class: ThemeCheck::ThemeFileRewriter
- Inherits:
-
Object
- Object
- ThemeCheck::ThemeFileRewriter
- Defined in:
- lib/theme_check/theme_file_rewriter.rb
Instance Method Summary collapse
-
#initialize(name, source) ⇒ ThemeFileRewriter
constructor
A new instance of ThemeFileRewriter.
- #insert_after(node, content) ⇒ Object
- #insert_before(node, content) ⇒ Object
- #replace(node, content) ⇒ Object
- #to_s ⇒ Object
- #wrap(node, insert_before, insert_after) ⇒ Object
Constructor Details
#initialize(name, source) ⇒ ThemeFileRewriter
Returns a new instance of ThemeFileRewriter.
7 8 9 10 11 12 |
# File 'lib/theme_check/theme_file_rewriter.rb', line 7 def initialize(name, source) @buffer = Parser::Source::Buffer.new(name, source: source) @rewriter = Parser::Source::TreeRewriter.new( @buffer ) end |
Instance Method Details
#insert_after(node, content) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/theme_check/theme_file_rewriter.rb', line 21 def insert_after(node, content) @rewriter.insert_after( range(node.start_index, node.end_index), content ) end |
#insert_before(node, content) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/theme_check/theme_file_rewriter.rb', line 14 def insert_before(node, content) @rewriter.insert_before( range(node.start_index, node.end_index), content ) end |
#replace(node, content) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/theme_check/theme_file_rewriter.rb', line 28 def replace(node, content) @rewriter.replace( range(node.start_index, node.end_index), content ) end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/theme_check/theme_file_rewriter.rb', line 43 def to_s @rewriter.process end |
#wrap(node, insert_before, insert_after) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/theme_check/theme_file_rewriter.rb', line 35 def wrap(node, insert_before, insert_after) @rewriter.wrap( range(node.start_index, node.end_index), insert_before, insert_after, ) end |