Class: GraphQL::Upgrader::ConfigurationToKwargTransform

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

Overview

Find a configuration in the block and move it to a kwarg, for example do property :thing end becomes: property: thing

Instance Method Summary collapse

Methods inherited from Transform

#apply_processor, #normalize_type_expression, #reindent_lines, #trim_lines, #underscorize

Constructor Details

#initialize(kwarg:) ⇒ ConfigurationToKwargTransform

Returns a new instance of ConfigurationToKwargTransform.



218
219
220
# File 'lib/graphql/upgrader/member.rb', line 218

def initialize(kwarg:)
  @kwarg = kwarg
end

Instance Method Details

#apply(input_text) ⇒ Object



222
223
224
225
226
227
228
229
230
231
232
# File 'lib/graphql/upgrader/member.rb', line 222

def apply(input_text)
  input_text.gsub(
    /(?<field>(?:field|return_field|input_field|connection|argument).*) do(?<block_contents>.*?)[ ]*#{@kwarg} (?<kwarg_value>.*?)\n/m
  ) do
    field = $~[:field]
    block_contents = $~[:block_contents]
    kwarg_value = $~[:kwarg_value].strip

    "#{field}, #{@kwarg}: #{kwarg_value} do#{block_contents}"
  end
end