Class: RuboCop::RSpec::Corrector::MoveNode
- Inherits:
-
Object
- Object
- RuboCop::RSpec::Corrector::MoveNode
- Includes:
- 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
-
#corrector ⇒ Object
readonly
Returns the value of attribute corrector.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#processed_source ⇒ Object
readonly
Returns the value of attribute processed_source.
Instance Method Summary collapse
-
#initialize(node, corrector, processed_source) ⇒ MoveNode
constructor
A new instance of MoveNode.
- #move_after(other) ⇒ Object
- #move_before(other) ⇒ Object
Methods included from Cop::RSpec::FinalEndLocation
Constructor Details
#initialize(node, corrector, processed_source) ⇒ MoveNode
Returns a new instance of MoveNode.
13 14 15 16 17 |
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 13 def initialize(node, corrector, processed_source) @original = node @corrector = corrector @processed_source = processed_source # used by RangeHelp end |
Instance Attribute Details
#corrector ⇒ Object (readonly)
Returns the value of attribute corrector.
11 12 13 |
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 11 def corrector @corrector end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
11 12 13 |
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 11 def original @original end |
#processed_source ⇒ Object (readonly)
Returns the value of attribute processed_source.
11 12 13 |
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 11 def processed_source @processed_source end |
Instance Method Details
#move_after(other) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 28 def move_after(other) position = final_end_location(other) indent = ' ' * other.loc.column newline_indent = "\n#{indent}" corrector.insert_after(position, newline_indent + source(original)) corrector.remove(node_range_with_surrounding_space(original)) end |
#move_before(other) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/rubocop/rspec/corrector/move_node.rb', line 19 def move_before(other) position = other.loc.expression indent = ' ' * other.loc.column newline_indent = "\n#{indent}" corrector.insert_before(position, source(original) + newline_indent) corrector.remove(node_range_with_surrounding_space(original)) end |