class GraphQL::Upgrader::ProcToClassMethodTransform

def apply(input_text)

def apply(input_text)
  if input_text =~ @proc_check_pattern
    processor = apply_processor(input_text, NamedProcProcessor.new(@proc_name))
    processor.proc_to_method_sections.reverse.each do |proc_to_method_section|
      proc_body = input_text[proc_to_method_section.proc_body_start..proc_to_method_section.proc_body_end]
      method_defn_indent = " " * proc_to_method_section.proc_defn_indent
      method_defn = "def self.#{@proc_name}(#{proc_to_method_section.proc_arg_names.join(", ")})\n#{method_defn_indent}  #{proc_body}\n#{method_defn_indent}end\n"
      method_defn = trim_lines(method_defn)
      # replace the proc with the new method
      input_text[proc_to_method_section.proc_defn_start..proc_to_method_section.proc_defn_end] = method_defn
    end
  end
  input_text
end

def initialize(proc_name)

Parameters:
  • proc_name (String) -- The name of the proc to be moved to `def self.#{proc_name}`
def initialize(proc_name)
  @proc_name = proc_name
  # This will tell us whether to operate on the input or not
  @proc_check_pattern = /#{proc_name}\s?->/
end