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.


428
429
430
# File 'lib/graphql/upgrader/member.rb', line 428

def initialize
  @keys_to_upgrade = []
end

Instance Attribute Details

#keys_to_upgradeObject (readonly)

Returns the value of attribute keys_to_upgrade


427
428
429
# File 'lib/graphql/upgrader/member.rb', line 427

def keys_to_upgrade
  @keys_to_upgrade
end

Instance Method Details

#on_def(node) ⇒ Object


432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/graphql/upgrader/member.rb', line 432

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