Class: GraphQL::Upgrader::MutationDefineToClassTransform

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

Overview

Turns {X} = GraphQL::Relay::Mutation.define do into class {X} < Mutations::BaseMutation

Instance Method Summary collapse

Methods inherited from Transform

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

Constructor Details

#initialize(base_class_name: "Mutations::BaseMutation") ⇒ MutationDefineToClassTransform

Returns a new instance of MutationDefineToClassTransform

Parameters:

  • base_class_name (String)

    Replacement pattern for the base class name. Use this if your Mutation base class has a nonstandard name.



118
119
120
121
# File 'lib/graphql/upgrader/member.rb', line 118

def initialize(base_class_name: "Mutations::BaseMutation")
  @find_pattern = /([a-zA-Z_0-9:]*) = GraphQL::Relay::Mutation.define do/
  @replace_pattern = "class \\1 < #{base_class_name}"
end

Instance Method Details

#apply(input_text) ⇒ Object



123
124
125
# File 'lib/graphql/upgrader/member.rb', line 123

def apply(input_text)
  input_text.sub(@find_pattern, @replace_pattern)
end