class GraphQL::Upgrader::ProcToClassMethodTransform
Public Class Methods
new(proc_name)
click to toggle source
@param proc_name [String] The name of the proc to be moved to `def self.#{proc_name}`
# File lib/graphql/upgrader/member.rb, line 279 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
Public Instance Methods
apply(input_text)
click to toggle source
# File lib/graphql/upgrader/member.rb, line 285 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