Class: RuboCop::RSpec::Corrector::MoveNode

Inherits:
Object
  • Object
show all
Includes:
Cop::RSpec::CommentsHelp, Cop::RSpec::FinalEndLocation, Cop::RangeHelp
Defined in:
lib/rubocop/rspec/corrector/move_node.rb

Overview

Helper methods to move a node

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cop::RSpec::FinalEndLocation

#final_end_location

Methods included from Cop::RSpec::CommentsHelp

#begin_pos_with_comment, #buffer, #end_line_position, #source_range_with_comment, #start_line_position

Constructor Details

#initialize(node, corrector, processed_source) ⇒ MoveNode

Returns a new instance of MoveNode.



14
15
16
17
18
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 14

def initialize(node, corrector, processed_source)
  @original = node
  @corrector = corrector
  @processed_source = processed_source # used by RangeHelp
end

Instance Attribute Details

#correctorObject (readonly)

Returns the value of attribute corrector.



12
13
14
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 12

def corrector
  @corrector
end

#originalObject (readonly)

Returns the value of attribute original.



12
13
14
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 12

def original
  @original
end

#processed_sourceObject (readonly)

Returns the value of attribute processed_source.



12
13
14
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 12

def processed_source
  @processed_source
end

Instance Method Details

#move_after(other) ⇒ Object



27
28
29
30
31
32
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 27

def move_after(other)
  position = end_line_position(other)

  corrector.insert_after(position, "\n#{source(original)}")
  corrector.remove(node_range_with_surrounding_space(original))
end

#move_before(other) ⇒ Object



20
21
22
23
24
25
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 20

def move_before(other)
  position = start_line_position(other)

  corrector.insert_before(position, "#{source(original)}\n")
  corrector.remove(node_range_with_surrounding_space(original))
end