Class: Spoom::Deadcode::Remover::NodeRemover
- Inherits:
-
Object
- Object
- Spoom::Deadcode::Remover::NodeRemover
- Extended by:
- T::Sig
- Defined in:
- lib/spoom/deadcode/remover.rb
Instance Attribute Summary collapse
-
#new_source ⇒ Object
readonly
Returns the value of attribute new_source.
Instance Method Summary collapse
- #apply_edit ⇒ Object
-
#initialize(source, kind, location) ⇒ NodeRemover
constructor
A new instance of NodeRemover.
Constructor Details
#initialize(source, kind, location) ⇒ NodeRemover
Returns a new instance of NodeRemover.
36 37 38 39 40 41 42 43 |
# File 'lib/spoom/deadcode/remover.rb', line 36 def initialize(source, kind, location) @old_source = source @new_source = T.let(source.dup, String) @kind = kind @location = location @node_context = T.let(NodeFinder.find(source, location, kind), NodeContext) end |
Instance Attribute Details
#new_source ⇒ Object (readonly)
Returns the value of attribute new_source.
33 34 35 |
# File 'lib/spoom/deadcode/remover.rb', line 33 def new_source @new_source end |
Instance Method Details
#apply_edit ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/spoom/deadcode/remover.rb', line 46 def apply_edit sclass_context = @node_context.sclass_context if sclass_context delete_node_and_comments_and_sigs(sclass_context) return end node = @node_context.node case node when Prism::ClassNode, Prism::ModuleNode, Prism::DefNode delete_node_and_comments_and_sigs(@node_context) when Prism::ConstantWriteNode, Prism::ConstantOperatorWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOrWriteNode, Prism::ConstantPathWriteNode, Prism::ConstantPathOperatorWriteNode, Prism::ConstantPathAndWriteNode, Prism::ConstantPathOrWriteNode, Prism::ConstantTargetNode delete_constant_assignment(@node_context) when Prism::SymbolNode # for attr accessors delete_attr_accessor(@node_context) else raise Error, "Unsupported node type: #{node.class}" end end |