Class: GraphQL::Upgrader::ResolveProcToMethodTransform::ResolveProcProcessor

Inherits:
Parser::AST::Processor
  • Object
show all
Defined in:
lib/graphql/upgrader/member.rb

Defined Under Namespace

Classes: ResolveProcSection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResolveProcProcessor

Returns a new instance of ResolveProcProcessor.



590
591
592
# File 'lib/graphql/upgrader/member.rb', line 590

def initialize
  @resolve_proc_sections = []
end

Instance Attribute Details

#resolve_proc_sectionsObject (readonly)

Returns the value of attribute resolve_proc_sections.



589
590
591
# File 'lib/graphql/upgrader/member.rb', line 589

def resolve_proc_sections
  @resolve_proc_sections
end

Instance Method Details

#on_block(node) ⇒ Object



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
# File 'lib/graphql/upgrader/member.rb', line 620

def on_block(node)
  send_node, args_node, body_node = node.children
  _receiver, method_name, _send_args_node = *send_node
  # Assume that the first three-argument proc we enter is the resolve
  if (
    method_name == :lambda && args_node.children.size == 3 &&
    !@resolve_proc_sections.empty? && @resolve_proc_sections[-1].proc_arg_names.nil?
  )
    resolve_proc_section = @resolve_proc_sections[-1]
    source_exp = body_node.loc.expression
    resolve_proc_section.proc_arg_names = args_node.children.map { |arg_node| arg_node.children[0].to_s }
    resolve_proc_section.proc_start = source_exp.begin.begin_pos
    resolve_proc_section.proc_end = source_exp.end.end_pos
  end
  super(node)
end

#on_send(node) ⇒ Object



606
607
608
609
610
611
612
613
614
615
616
617
618
# File 'lib/graphql/upgrader/member.rb', line 606

def on_send(node)
  receiver, method_name, _args = *node
  if method_name == :resolve && receiver.nil?
    resolve_proc_section = ResolveProcSection.new
    source_exp = node.loc.expression
    resolve_proc_section.resolve_start = source_exp.begin.begin_pos
    resolve_proc_section.resolve_end = source_exp.end.end_pos
    resolve_proc_section.resolve_indent = source_exp.column

    @resolve_proc_sections << resolve_proc_section
  end
  super(node)
end