Class: PlatformosCheck::AppFileRewriter
- Inherits:
-
Object
- Object
- PlatformosCheck::AppFileRewriter
- Defined in:
- lib/platformos_check/app_file_rewriter.rb
Instance Method Summary collapse
-
#initialize(name, source) ⇒ AppFileRewriter
constructor
A new instance of AppFileRewriter.
- #insert_after(node, content, character_range = nil) ⇒ Object
- #insert_before(node, content, character_range = nil) ⇒ Object
- #remove(node) ⇒ Object
- #replace(node, content, character_range = nil) ⇒ Object
- #replace_inner_markup(node, content) ⇒ Object
- #to_s ⇒ Object
- #wrap(node, insert_before, insert_after) ⇒ Object
Constructor Details
#initialize(name, source) ⇒ AppFileRewriter
Returns a new instance of AppFileRewriter.
7 8 9 10 11 12 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 7 def initialize(name, source) @buffer = Parser::Source::Buffer.new(name, source:) @rewriter = Parser::Source::TreeRewriter.new( @buffer ) end |
Instance Method Details
#insert_after(node, content, character_range = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 24 def insert_after(node, content, character_range = nil) @rewriter.insert_after( range( character_range&.begin || node.start_index, character_range&.end || node.end_index ), content ) end |
#insert_before(node, content, character_range = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 14 def insert_before(node, content, character_range = nil) @rewriter.insert_before( range( character_range&.begin || node.start_index, character_range&.end || node.end_index ), content ) end |
#remove(node) ⇒ Object
34 35 36 37 38 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 34 def remove(node) @rewriter.remove( range(node.outer_markup_start_index, node.outer_markup_end_index) ) end |
#replace(node, content, character_range = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 40 def replace(node, content, character_range = nil) @rewriter.replace( range( character_range&.begin || node.start_index, character_range&.end || node.end_index ), content ) end |
#replace_inner_markup(node, content) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 50 def replace_inner_markup(node, content) @rewriter.replace( range(node.inner_markup_start_index, node.inner_markup_end_index), content ) end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 65 def to_s @rewriter.process end |
#wrap(node, insert_before, insert_after) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/platformos_check/app_file_rewriter.rb', line 57 def wrap(node, insert_before, insert_after) @rewriter.wrap( range(node.start_index, node.end_index), insert_before, insert_after ) end |