class GraphQL::Upgrader::Member::FieldFinder
def add_location(send_node:,source_node:)
-
source_node
(node
) -- The node whose source defines the bounds of the definition (eg, the surrounding block) -
send_node
(node
) -- The node which might be a `field` call, etc
def add_location(send_node:,source_node:) receiver_node, method_name, *arg_nodes = *send_node # Implicit self and one of the recognized methods if receiver_node.nil? && DEFINITION_METHODS.include?(method_name) name = arg_nodes[0] # This field may have already been added because # we find `(block ...)` nodes _before_ we find `(send ...)` nodes. if @locations[method_name][name].nil? starting_idx = source_node.loc.expression.begin.begin_pos ending_idx = source_node.loc.expression.end.end_pos @locations[method_name][name] = [starting_idx, ending_idx] end end end
def initialize
def initialize # Pairs of `{ { method_name => { name => [start, end] } }`, # since fields/arguments are unique by name, within their category @locations = Hash.new { |h,k| h[k] = {} } end
def on_block(node)
def on_block(node) send_node, _args_node, _body_node = *node add_location(send_node: send_node, source_node: node) super(node) end
def on_send(node)
def on_send(node) add_location(send_node: node, source_node: node) super(node) end