Class: GraphQL::Upgrader::TypeDefineToClassTransform
- Defined in:
- lib/graphql/upgrader/member.rb
Overview
Turns {X} = GraphQL::{Y}Type.define do
into class {X} < Types::Base{Y}
.
Instance Method Summary collapse
-
#apply(input_text) ⇒ Object
-
#initialize(base_class_pattern: "Types::Base\\3") ⇒ TypeDefineToClassTransform
constructor
A new instance of TypeDefineToClassTransform.
Methods inherited from Transform
#apply_processor, #normalize_type_expression, #reindent_lines, #trim_lines, #underscorize
Constructor Details
#initialize(base_class_pattern: "Types::Base\\3") ⇒ TypeDefineToClassTransform
Returns a new instance of TypeDefineToClassTransform
104 105 106 107 108 |
# File 'lib/graphql/upgrader/member.rb', line 104 def initialize(base_class_pattern: "Types::Base\\3") @find_pattern = /( *)([a-zA-Z_0-9:]*) = GraphQL::#{GRAPHQL_TYPES}Type\.define do/ @replace_pattern = "\\1class \\2 < #{base_class_pattern}" @interface_replace_pattern = "\\1module \\2\n\\1 include #{base_class_pattern}" end |
Instance Method Details
#apply(input_text) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/graphql/upgrader/member.rb', line 110 def apply(input_text) if input_text.include?("GraphQL::InterfaceType.define") input_text.sub(@find_pattern, @interface_replace_pattern) else input_text.sub(@find_pattern, @replace_pattern) end end |