Class: Synvert::Core::Rewriter::AppendAction

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

Overview

AppendAction to append code to the bottom of node body.

Constant Summary collapse

END_LENGTH =
"\nend".length

Constants inherited from Action

Synvert::Core::Rewriter::Action::DEFAULT_INDENT, Synvert::Core::Rewriter::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 append code.

Returns:

  • (Integer)

    begin position.



11
12
13
14
15
16
17
# File 'lib/synvert/core/rewriter/action/append_action.rb', line 11

def begin_pos
  if :begin == @node.type
    @node.loc.expression.end_pos
  else
    @node.loc.expression.end_pos - @node.indent - END_LENGTH
  end
end

#end_posInteger

End position, always same to begin position.

Returns:

  • (Integer)

    end position.



22
23
24
# File 'lib/synvert/core/rewriter/action/append_action.rb', line 22

def end_pos
  begin_pos
end