Class: XDry::InsideConstructorIfSuperIP

Inherits:
InsertionPoint show all
Defined in:
lib/xdry/patching/insertion_points.rb

Instance Attribute Summary

Attributes inherited from InsertionPoint

#ip, #method, #node

Instance Method Summary collapse

Methods inherited from InsertionPoint

#found?, #insert

Constructor Details

#initialize(scope) ⇒ InsideConstructorIfSuperIP

Returns a new instance of InsideConstructorIfSuperIP.



156
157
158
159
# File 'lib/xdry/patching/insertion_points.rb', line 156

def initialize scope
  @scope = scope
  super()
end

Instance Method Details

#find!Object



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/xdry/patching/insertion_points.rb', line 161

def find!
  if_start_node = @scope.children.find { |child| child.is_a? NSuperCall }
  if if_start_node.nil?
    indented_before @scope.ending_node
  else
    if_end_node = @scope.children.find { |child| child.is_a?(NClosingBrace) && child.indent == if_start_node.indent }
    if if_end_node.nil?
      indented_after if_start_node
    else
      indented_before if_end_node
    end
  end
end