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.



567
568
569
570
571
572
573
574
# File 'lib/graphql/upgrader/member.rb', line 567

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.



566
567
568
# File 'lib/graphql/upgrader/member.rb', line 566

def proc_arg_names
  @proc_arg_names
end

#proc_endObject (readonly)

Returns the value of attribute proc_end.



566
567
568
# File 'lib/graphql/upgrader/member.rb', line 566

def proc_end
  @proc_end
end

#proc_startObject (readonly)

Returns the value of attribute proc_start.



566
567
568
# File 'lib/graphql/upgrader/member.rb', line 566

def proc_start
  @proc_start
end

#resolve_endObject (readonly)

Returns the value of attribute resolve_end.



566
567
568
# File 'lib/graphql/upgrader/member.rb', line 566

def resolve_end
  @resolve_end
end

#resolve_indentObject (readonly)

Returns the value of attribute resolve_indent.



566
567
568
# File 'lib/graphql/upgrader/member.rb', line 566

def resolve_indent
  @resolve_indent
end

#resolve_startObject (readonly)

Returns the value of attribute resolve_start.



566
567
568
# File 'lib/graphql/upgrader/member.rb', line 566

def resolve_start
  @resolve_start
end

Instance Method Details

#on_block(node) ⇒ Object



587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/graphql/upgrader/member.rb', line 587

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



576
577
578
579
580
581
582
583
584
585
# File 'lib/graphql/upgrader/member.rb', line 576

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