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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResolveProcProcessor

Returns a new instance of ResolveProcProcessor



563
564
565
566
567
568
569
570
# File 'lib/graphql/upgrader/member.rb', line 563

def initialize
  @proc_arg_names = nil
  @resolve_start = nil
  @resolve_end = nil
  @resolve_indent = nil
  @proc_start = nil
  @proc_end = nil
end

Instance Attribute Details

#proc_arg_namesObject (readonly)

Returns the value of attribute proc_arg_names



562
563
564
# File 'lib/graphql/upgrader/member.rb', line 562

def proc_arg_names
  @proc_arg_names
end

#proc_endObject (readonly)

Returns the value of attribute proc_end



562
563
564
# File 'lib/graphql/upgrader/member.rb', line 562

def proc_end
  @proc_end
end

#proc_startObject (readonly)

Returns the value of attribute proc_start



562
563
564
# File 'lib/graphql/upgrader/member.rb', line 562

def proc_start
  @proc_start
end

#resolve_endObject (readonly)

Returns the value of attribute resolve_end



562
563
564
# File 'lib/graphql/upgrader/member.rb', line 562

def resolve_end
  @resolve_end
end

#resolve_indentObject (readonly)

Returns the value of attribute resolve_indent



562
563
564
# File 'lib/graphql/upgrader/member.rb', line 562

def resolve_indent
  @resolve_indent
end

#resolve_startObject (readonly)

Returns the value of attribute resolve_start



562
563
564
# File 'lib/graphql/upgrader/member.rb', line 562

def resolve_start
  @resolve_start
end

Instance Method Details

#on_block(node) ⇒ Object



583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/graphql/upgrader/member.rb', line 583

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 && @proc_arg_names.nil?
    source_exp = body_node.loc.expression
    @proc_arg_names = args_node.children.map { |arg_node| arg_node.children[0].to_s }
    @proc_start = source_exp.begin.begin_pos
    @proc_end = source_exp.end.end_pos
  end
  super(node)
end

#on_send(node) ⇒ Object



572
573
574
575
576
577
578
579
580
581
# File 'lib/graphql/upgrader/member.rb', line 572

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