Class: GraphqlMigrateExecution::Strategy
- Inherits:
-
Object
- Object
- GraphqlMigrateExecution::Strategy
show all
- Includes:
- Action::Colorize
- Defined in:
- lib/graphql_migrate_execution/strategy.rb
Direct Known Subclasses
DataloaderAll, DataloaderManual, DataloaderShorthand, DoNothing, FallbackValue, HashKey, Implicit, NotImplemented, ResolveBatch, ResolveEach, ResolveStatic, UnsupportedCurrentPath, UnsupportedExtra
Constant Summary
collapse
- METHODS_TO_RENAME =
These methods conflict with built-in class methods, so when migrating them, prefix them.
[
"name",
"fields",
"arguments",
]
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(action, field_definitions) ⇒ Strategy
Returns a new instance of Strategy.
7
8
9
10
11
12
13
14
15
|
# File 'lib/graphql_migrate_execution/strategy.rb', line 7
def initialize(action, field_definitions)
@action = action
@migration = action.migration
@filepath = action.filepath
@action_method = @migration.action_method
@message = action.message
@result_source = action.result_source
@field_definitions = field_definitions
end
|
Class Attribute Details
.color ⇒ Object
Returns the value of attribute color.
52
53
54
|
# File 'lib/graphql_migrate_execution/strategy.rb', line 52
def color
@color
end
|
Class Method Details
.prefix_if_necessary(method_name) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/graphql_migrate_execution/strategy.rb', line 63
def self.prefix_if_necessary(method_name)
name_s = method_name.to_s
if METHODS_TO_RENAME.include?(name_s)
"resolve_#{method_name}"
else
name_s
end
end
|
.strategy_name ⇒ Object
47
48
49
|
# File 'lib/graphql_migrate_execution/strategy.rb', line 47
def self.strategy_name
name.split("::").last
end
|
Instance Method Details
#cleanup(field_definition) ⇒ Object
20
21
|
# File 'lib/graphql_migrate_execution/strategy.rb', line 20
def cleanup(field_definition)
end
|
#migrate(field_definition) ⇒ Object
17
18
|
# File 'lib/graphql_migrate_execution/strategy.rb', line 17
def migrate(field_definition)
end
|
#run ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/graphql_migrate_execution/strategy.rb', line 23
def run
case @action_method
when :analyze
@message << "\n#{colorize("#{colorize(self.class.strategy_name, self.class.color)} (#{@field_definitions.size})", :BOLD)}:\n"
max_path = @field_definitions.map { |f| f.path.size }.max + 2
@field_definitions.each do |field_defn|
name = field_defn.path.ljust(max_path)
@message << "\n - #{name} (#{field_defn.resolve_mode.inspect} -> #{field_defn.resolve_mode_key.inspect}) @ #{@filepath}:#{field_defn.source_line}"
end
@message << "\n"
when :migrate, :cleanup
indent_size = @action.strategy_name_padding + 1
indent = " " * indent_size
indent2_size = @action.field_name_padding
@message << "\n#{colorize(self.class.strategy_name.ljust(indent_size), self.class.color)}"
first = true
@field_definitions.each do |field_defn|
@message << "#{first ? "" : "#{indent}"}#{field_defn.path.ljust(indent2_size)} @ #{@filepath}:#{field_defn.source_line}\n"
first = false
public_send(@action_method, field_defn)
end
end
end
|