Class: GraphQL::Upgrader::RemoveNewlinesTransform

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

Overview

Remove newlines -- normalize the text for processing

Instance Method Summary collapse

Instance Method Details

#apply(input_text) ⇒ Object


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/graphql/upgrader/member.rb', line 164

def apply(input_text)
  keep_looking = true
  while keep_looking do
    keep_looking = false
    # Find the `field` call (or other method), and an open paren, but not a close paren, or a comma between arguments
    input_text = input_text.gsub(/(?<field>(?:field|input_field|return_field|connection|argument)(?:\([^)]*|.*,))\n\s*(?<next_line>.+)/) do
      keep_looking = true
      field = $~[:field].chomp
      next_line = $~[:next_line]

      "#{field} #{next_line}"
    end
  end
  input_text
end