Class: GraphQL::Upgrader::UnderscorizeMutationHashTransform::ReturnedHashLiteralProcessor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReturnedHashLiteralProcessor

Returns a new instance of ReturnedHashLiteralProcessor



403
404
405
# File 'lib/graphql/upgrader/member.rb', line 403

def initialize
  @keys_to_upgrade = []
end

Instance Attribute Details

#keys_to_upgradeObject (readonly)

Returns the value of attribute keys_to_upgrade



402
403
404
# File 'lib/graphql/upgrader/member.rb', line 402

def keys_to_upgrade
  @keys_to_upgrade
end

Instance Method Details

#on_def(node) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/graphql/upgrader/member.rb', line 407

def on_def(node)
  method_name, _args, body = *node
  if method_name == :resolve
    possible_returned_hashes = find_returned_hashes(body, returning: false)
    possible_returned_hashes.each do |hash_node|
      pairs = *hash_node
      pairs.each do |pair_node|
        if pair_node.type == :pair # Skip over :kwsplat
          pair_k, _pair_v = *pair_node
          if pair_k.type == :sym && pair_k.children[0].to_s =~ /[a-z][A-Z]/ # Does it have any camelcase boundaries?
            source_exp = pair_k.loc.expression
            @keys_to_upgrade << {
              start: source_exp.begin.begin_pos,
              end: source_exp.end.end_pos,
              key: pair_k.children[0],
              operator: pair_node.loc.operator.source,
            }
          end
        end
      end
    end
  end

end