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 274 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 280 def apply(input_text) if input_text =~ @proc_check_pattern processor = apply_processor(input_text, NamedProcProcessor.new(@proc_name)) proc_body = input_text[processor.proc_body_start..processor.proc_body_end] method_defn_indent = " " * processor.proc_defn_indent method_defn = "def self.#{@proc_name}(#{processor.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[processor.proc_defn_start..processor.proc_defn_end] = method_defn end input_text end