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



214
215
216
# File 'lib/graphql/upgrader/member.rb', line 214

def initialize(kwarg:)
  @kwarg = kwarg
end

Instance Method Details

#apply(input_text) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/graphql/upgrader/member.rb', line 218

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