Class: GraphQL::Upgrader::UnderscorizeMutationHashTransform::ReturnedHashLiteralProcessor
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- GraphQL::Upgrader::UnderscorizeMutationHashTransform::ReturnedHashLiteralProcessor
- Defined in:
- lib/graphql/upgrader/member.rb
Instance Attribute Summary collapse
-
#keys_to_upgrade ⇒ Object
readonly
Returns the value of attribute keys_to_upgrade.
Instance Method Summary collapse
-
#initialize ⇒ ReturnedHashLiteralProcessor
constructor
A new instance of ReturnedHashLiteralProcessor.
-
#on_def(node) ⇒ Object
Constructor Details
#initialize ⇒ ReturnedHashLiteralProcessor
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_upgrade ⇒ Object (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 |