Class: Synvert::Core::Rewriter::PrependAction

Inherits:
Action
  • Object
show all
Defined in:
lib/synvert/core/rewriter/action/prepend_action.rb

Overview

PrependAction to prepend code to the top of node body.

Constant Summary collapse

DO_LENGTH =
' do'.length

Constants inherited from Action

Action::DEFAULT_INDENT, Action::DEFAULT_OPTIONS

Instance Method Summary collapse

Methods inherited from Action

#initialize, #line, #rewritten_code, #rewritten_source

Constructor Details

This class inherits a constructor from Synvert::Core::Rewriter::Action

Instance Method Details

#begin_posInteger

Begin position to prepend code.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/synvert/core/rewriter/action/prepend_action.rb', line 11

def begin_pos
  case @node.type
  when :block
    if @node.children[1].children.empty?
      @node.children[0].loc.expression.end_pos + DO_LENGTH
    else
      @node.children[1].loc.expression.end_pos
    end
  when :class
    @node.children[1] ? @node.children[1].loc.expression.end_pos : @node.children[0].loc.expression.end_pos
  else
    @node.children.last.loc.expression.end_pos
  end
end

#end_posInteger

End position, always same to begin position.



29
30
31
# File 'lib/synvert/core/rewriter/action/prepend_action.rb', line 29

def end_pos
  begin_pos
end