reweave 0.1.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/reweave/execution/engine.rb +6 -0
- data/lib/reweave/execution/execution_context.rb +4 -0
- data/lib/reweave/recipe/recipe_option.rb +2 -1
- data/lib/reweave/recipes/rails/solid_cache_migration.rb +1 -20
- data/lib/reweave/recipes/rails/solid_queue_migration.rb +1 -13
- data/lib/reweave/recipes/rails/update_active_record.rb +5 -5
- data/lib/reweave/recipes/rails/upgrade_2_3_to_3_0.rb +59 -0
- data/lib/reweave/recipes/rails/upgrade_3_0_to_3_1.rb +42 -0
- data/lib/reweave/recipes/rails/upgrade_3_1_to_3_2.rb +39 -0
- data/lib/reweave/recipes/rails/upgrade_3_2_to_4_0.rb +81 -0
- data/lib/reweave/recipes/rails/upgrade_4_0_to_4_1.rb +39 -0
- data/lib/reweave/recipes/rails/upgrade_4_1_to_4_2.rb +46 -0
- data/lib/reweave/recipes/rails/upgrade_4_2_to_5_0.rb +77 -0
- data/lib/reweave/recipes/rails/upgrade_5_0_to_5_1.rb +51 -0
- data/lib/reweave/recipes/rails/upgrade_5_1_to_5_2.rb +54 -0
- data/lib/reweave/recipes/rails/upgrade_5_2_to_6_0.rb +57 -0
- data/lib/reweave/recipes/rails/upgrade_6_0_to_6_1.rb +45 -0
- data/lib/reweave/recipes/rails/upgrade_6_1_to_7_0.rb +81 -0
- data/lib/reweave/recipes/rails/upgrade_7_0_to_7_1.rb +46 -0
- data/lib/reweave/recipes/rails/upgrade_7_1_to_7_2.rb +51 -0
- data/lib/reweave/recipes/rails/upgrade_7_2_to_8_0.rb +82 -0
- data/lib/reweave/recipes/rails/upgrade_8_0_to_8_1.rb +37 -0
- data/lib/reweave/recipes/rails/upgrade_rails.rb +36 -2
- data/lib/reweave/recipes/ruby/modernize_syntax.rb +6 -17
- data/lib/reweave/recipes/ruby/upgrade_1_8_to_1_9.rb +76 -0
- data/lib/reweave/recipes/ruby/upgrade_1_9_to_2_0.rb +67 -0
- data/lib/reweave/recipes/ruby/upgrade_2_0_to_2_1.rb +50 -0
- data/lib/reweave/recipes/ruby/upgrade_2_1_to_2_2.rb +48 -0
- data/lib/reweave/recipes/ruby/upgrade_2_2_to_2_3.rb +75 -0
- data/lib/reweave/recipes/ruby/upgrade_2_3_to_2_4.rb +74 -0
- data/lib/reweave/recipes/ruby/upgrade_2_4_to_2_5.rb +53 -0
- data/lib/reweave/recipes/ruby/upgrade_2_5_to_2_6.rb +57 -0
- data/lib/reweave/recipes/ruby/upgrade_2_6_to_2_7.rb +71 -0
- data/lib/reweave/recipes/ruby/upgrade_2_7_to_3_0.rb +122 -0
- data/lib/reweave/recipes/ruby/upgrade_3_0_to_3_1.rb +50 -0
- data/lib/reweave/recipes/ruby/upgrade_3_1_to_3_2.rb +37 -0
- data/lib/reweave/recipes/ruby/upgrade_3_2_to_3_3.rb +37 -0
- data/lib/reweave/recipes/ruby/upgrade_3_3_to_4_0.rb +37 -0
- data/lib/reweave/recipes/ruby/upgrade_ruby.rb +49 -0
- data/lib/reweave/semantic/analyzer.rb +30 -0
- data/lib/reweave/semantic/symbol.rb +40 -0
- data/lib/reweave/semantic/symbol_collector.rb +159 -0
- data/lib/reweave/semantic/symbol_table.rb +100 -0
- data/lib/reweave/version.rb +1 -1
- data/lib/reweave/visitor/recipe_helpers.rb +222 -0
- data/lib/reweave/visitor/ruby_visitor.rb +3 -0
- metadata +37 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e41938bdeb36c49d0fc6b78587e24054fcf219c50ec08f18809b14ffb12e14b7
|
|
4
|
+
data.tar.gz: fd706682b8e82d35cc708d94e2d16a234f0d2ac5db16d4002762c57e7faf2079
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e75501890d62f60bb084efc2467b3e0fa0bc13415a83ef04ebb17a3311e5b59acad648db0e5958c9031c9a4be6ec1f617f88847b10711120c0c2ba7e7d63cc38
|
|
7
|
+
data.tar.gz: 3eb6bc74f6978a04da4b81e13e5afbb74fa8a473172d33535ff2375b9383599d30c41a35c4ff6463b6b4763807ff7443ec6a939b419451df151cff0dafd8d279
|
|
@@ -6,6 +6,7 @@ require_relative "project"
|
|
|
6
6
|
require_relative "../../reweave/results/execution_result"
|
|
7
7
|
require_relative "../../reweave/results/changeset"
|
|
8
8
|
require_relative "../../reweave/recipe/scanning_recipe"
|
|
9
|
+
require_relative "../../reweave/semantic/analyzer"
|
|
9
10
|
|
|
10
11
|
module Reweave
|
|
11
12
|
module Execution
|
|
@@ -75,6 +76,11 @@ module Reweave
|
|
|
75
76
|
project = Project.from_path(path, patterns: patterns || ["**/*.rb"], exclude: exclude || [])
|
|
76
77
|
@change_set = Results::ChangeSet.new
|
|
77
78
|
|
|
79
|
+
# Build cross-file symbol table for semantic analysis
|
|
80
|
+
symbol_table = Semantic::Analyzer.new(project).analyze
|
|
81
|
+
@context.symbol_table = symbol_table
|
|
82
|
+
@context.stats[:symbols_resolved] = symbol_table.size
|
|
83
|
+
|
|
78
84
|
# Expand composite recipes
|
|
79
85
|
expanded_recipes = expand_recipes(recipe)
|
|
80
86
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "../../reweave/semantic/symbol_table"
|
|
4
|
+
|
|
3
5
|
module Reweave
|
|
4
6
|
module Execution
|
|
5
7
|
class ExecutionContext
|
|
6
8
|
attr_reader :project_root, :dry_run, :max_cycles, :logger, :diagnostics, :messages, :metadata, :stats
|
|
9
|
+
attr_accessor :symbol_table
|
|
7
10
|
|
|
8
11
|
def initialize(project_root: ".", dry_run: true, max_cycles: 10, logger: nil)
|
|
9
12
|
@project_root = File.expand_path(project_root)
|
|
@@ -23,6 +26,7 @@ module Reweave
|
|
|
23
26
|
recipes_executed: 0,
|
|
24
27
|
total_edits: 0
|
|
25
28
|
}
|
|
29
|
+
@symbol_table = Semantic::SymbolTable.new
|
|
26
30
|
@cancelled = false
|
|
27
31
|
end
|
|
28
32
|
|
|
@@ -37,7 +37,8 @@ module Reweave
|
|
|
37
37
|
when Class, Module
|
|
38
38
|
value.is_a?(@type)
|
|
39
39
|
when Array
|
|
40
|
-
|
|
40
|
+
# Array type means union: value must match at least one of the types
|
|
41
|
+
@type.any? { |t| t.is_a?(Class) && value.is_a?(t) }
|
|
41
42
|
else
|
|
42
43
|
true
|
|
43
44
|
end
|
|
@@ -29,28 +29,9 @@ module Reweave
|
|
|
29
29
|
|
|
30
30
|
def visit_call_node(node)
|
|
31
31
|
# config.cache_store = :redis_cache_store -> :solid_cache_store
|
|
32
|
-
if match_call?(node, receiver: "config", method: :cache_store=)
|
|
33
|
-
args = extract_arguments(node)
|
|
34
|
-
if args.first&.is_a?(Prism::SymbolNode) && args.first.value == :redis_cache_store
|
|
35
|
-
replace(args.first, ":solid_cache_store")
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
32
|
# config.cache_store = :mem_cache_store -> :solid_cache_store
|
|
40
|
-
if match_call?(node, receiver: "config", method: :cache_store=)
|
|
41
|
-
args = extract_arguments(node)
|
|
42
|
-
if args.first&.is_a?(Prism::SymbolNode) && args.first.value == :mem_cache_store
|
|
43
|
-
replace(args.first, ":solid_cache_store")
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
33
|
# config.cache_store = :memory_store -> :solid_cache_store
|
|
48
|
-
|
|
49
|
-
args = extract_arguments(node)
|
|
50
|
-
if args.first&.is_a?(Prism::SymbolNode) && args.first.value == :memory_store
|
|
51
|
-
replace(args.first, ":solid_cache_store")
|
|
52
|
-
end
|
|
53
|
-
end
|
|
34
|
+
replace_config_value(node, %w[config], %w[redis_cache_store mem_cache_store memory_store], "solid_cache_store", method: :cache_store=)
|
|
54
35
|
|
|
55
36
|
super
|
|
56
37
|
end
|
|
@@ -29,20 +29,8 @@ module Reweave
|
|
|
29
29
|
|
|
30
30
|
def visit_call_node(node)
|
|
31
31
|
# config.active_job.queue_adapter = :sidekiq -> :solid_queue
|
|
32
|
-
if match_call?(node, receiver: "config.active_job", method: :queue_adapter=)
|
|
33
|
-
args = extract_arguments(node)
|
|
34
|
-
if args.first&.is_a?(Prism::SymbolNode) && args.first.value == :sidekiq
|
|
35
|
-
replace(args.first, ":solid_queue")
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
32
|
# config.active_job.queue_adapter = "sidekiq" -> "solid_queue"
|
|
40
|
-
|
|
41
|
-
args = extract_arguments(node)
|
|
42
|
-
if args.first&.is_a?(Prism::StringNode) && args.first.value == "sidekiq"
|
|
43
|
-
replace(args.first, "\"solid_queue\"")
|
|
44
|
-
end
|
|
45
|
-
end
|
|
33
|
+
replace_config_value(node, %w[config active_job], %w[sidekiq], "solid_queue", method: :queue_adapter=)
|
|
46
34
|
|
|
47
35
|
super
|
|
48
36
|
end
|
|
@@ -30,12 +30,12 @@ module Reweave
|
|
|
30
30
|
def visit_call_node(node)
|
|
31
31
|
# update_attributes -> update
|
|
32
32
|
if node.name == :update_attributes
|
|
33
|
-
|
|
33
|
+
replace_method_name(node, :update)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# update_attributes! -> update!
|
|
37
37
|
if node.name == :update_attributes!
|
|
38
|
-
|
|
38
|
+
replace_method_name(node, :update!)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# destroy_all with conditions -> where(...).destroy_all
|
|
@@ -55,9 +55,9 @@ module Reweave
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
# first/last with order -> order(...).first/last
|
|
58
|
-
if node.name == :first || node.name == :last
|
|
59
|
-
|
|
60
|
-
if
|
|
58
|
+
if (node.name == :first || node.name == :last) && call_with_args?(node, 1)
|
|
59
|
+
arg = first_arg(node, Prism::HashNode)
|
|
60
|
+
if arg
|
|
61
61
|
# Could have order: { created_at: :desc }
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 2.3 -> 3.0 syntax upgrades
|
|
10
|
+
class Upgrade23To30 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 2.3 to 3.0"
|
|
12
|
+
description "Converts Rails 2.3 syntax to 3.0: ActiveRecord query interface, routes, mailers, bundler, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_named_scope, type: [TrueClass, FalseClass], default: true, description: "Convert named_scope to scope"
|
|
15
|
+
option :convert_finders, type: [TrueClass, FalseClass], default: true, description: "Convert dynamic finders (find_by_*) to where"
|
|
16
|
+
option :convert_routes, type: [TrueClass, FalseClass], default: true, description: "Convert old routes syntax to new"
|
|
17
|
+
option :convert_mailers, type: [TrueClass, FalseClass], default: true, description: "Convert old mailer syntax"
|
|
18
|
+
|
|
19
|
+
def get_visitor(context)
|
|
20
|
+
Upgrade23To30Visitor.new(context, config)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Upgrade23To30Visitor < Reweave::Visitor::RubyVisitor
|
|
25
|
+
def initialize(context, config)
|
|
26
|
+
super(context, nil)
|
|
27
|
+
@config = config
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def run(source_file)
|
|
31
|
+
@source_file = source_file
|
|
32
|
+
traverse(source_file.root)
|
|
33
|
+
edits
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Convert named_scope to scope
|
|
37
|
+
def visit_call_node(node)
|
|
38
|
+
return super unless @config[:convert_named_scope]
|
|
39
|
+
|
|
40
|
+
if match_call?(node, method: :named_scope)
|
|
41
|
+
replace_location(node.message_loc, "scope")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Convert dynamic finders: find_by_name -> where(name: ...).first
|
|
45
|
+
if @config[:convert_finders] && node.name.to_s.start_with?("find_by_")
|
|
46
|
+
# This is complex, skip for now
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Convert old routes: map.root -> root
|
|
50
|
+
if @config[:convert_routes] && match_call?(node, method: :root) && match_call?(node.receiver, method: :map)
|
|
51
|
+
# map.root :controller => "home" -> root "home#index"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
super
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 3.0 -> 3.1 syntax upgrades
|
|
10
|
+
class Upgrade30To31 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 3.0 to 3.1"
|
|
12
|
+
description "Converts Rails 3.0 syntax to 3.1: asset pipeline, reversible migrations, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_assets, type: [TrueClass, FalseClass], default: true, description: "Convert asset paths"
|
|
15
|
+
option :convert_migrations, type: [TrueClass, FalseClass], default: true, description: "Convert reversible migrations"
|
|
16
|
+
|
|
17
|
+
def get_visitor(context)
|
|
18
|
+
Upgrade30To31Visitor.new(context, config)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Upgrade30To31Visitor < Reweave::Visitor::RubyVisitor
|
|
23
|
+
def initialize(context, config)
|
|
24
|
+
super(context, nil)
|
|
25
|
+
@config = config
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run(source_file)
|
|
29
|
+
@source_file = source_file
|
|
30
|
+
traverse(source_file.root)
|
|
31
|
+
edits
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def visit_call_node(node)
|
|
35
|
+
# Convert image_tag with old paths
|
|
36
|
+
# This is minimal for now
|
|
37
|
+
super
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 3.1 -> 3.2 syntax upgrades
|
|
10
|
+
class Upgrade31To32 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 3.1 to 3.2"
|
|
12
|
+
description "Converts Rails 3.1 syntax to 3.2: key-value store, tagged logging, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_key_value_store, type: [TrueClass, FalseClass], default: true, description: "Convert key-value store syntax"
|
|
15
|
+
|
|
16
|
+
def get_visitor(context)
|
|
17
|
+
Upgrade31To32Visitor.new(context, config)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class Upgrade31To32Visitor < Reweave::Visitor::RubyVisitor
|
|
22
|
+
def initialize(context, config)
|
|
23
|
+
super(context, nil)
|
|
24
|
+
@config = config
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def run(source_file)
|
|
28
|
+
@source_file = source_file
|
|
29
|
+
traverse(source_file.root)
|
|
30
|
+
edits
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def visit_call_node(node)
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 3.2 -> 4.0 syntax upgrades
|
|
10
|
+
class Upgrade32To40 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 3.2 to 4.0"
|
|
12
|
+
description "Converts Rails 3.2 syntax to 4.0: strong parameters, routing concerns, ActiveRecord::Relation changes, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_strong_parameters, type: [TrueClass, FalseClass], default: true, description: "Convert attr_accessible to strong parameters"
|
|
15
|
+
option :convert_routes, type: [TrueClass, FalseClass], default: true, description: "Convert match to HTTP verbs"
|
|
16
|
+
option :convert_scopes, type: [TrueClass, FalseClass], default: true, description: "Convert scope syntax"
|
|
17
|
+
option :convert_activerecord_relation, type: [TrueClass, FalseClass], default: true, description: "Convert ActiveRecord::Relation deprecations"
|
|
18
|
+
|
|
19
|
+
def get_visitor(context)
|
|
20
|
+
Upgrade32To40Visitor.new(context, config)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Upgrade32To40Visitor < Reweave::Visitor::RubyVisitor
|
|
25
|
+
def initialize(context, config)
|
|
26
|
+
super(context, nil)
|
|
27
|
+
@config = config
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def run(source_file)
|
|
31
|
+
@source_file = source_file
|
|
32
|
+
traverse(source_file.root)
|
|
33
|
+
edits
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def visit_call_node(node)
|
|
37
|
+
# Convert match to HTTP verbs
|
|
38
|
+
if @config[:convert_routes] && match_call?(node, method: :match)
|
|
39
|
+
args = extract_arguments(node)
|
|
40
|
+
if args.size == 1
|
|
41
|
+
path = args.first
|
|
42
|
+
# match "/path" -> get "/path"
|
|
43
|
+
replace(node, "get #{source_for(path)}")
|
|
44
|
+
elsif args.size == 2
|
|
45
|
+
path = args[0]
|
|
46
|
+
options = args[1]
|
|
47
|
+
if options.is_a?(Prism::HashNode)
|
|
48
|
+
# Check for :via option
|
|
49
|
+
via_value = options.elements.find do |e|
|
|
50
|
+
e.is_a?(Prism::AssocNode) && e.key.is_a?(Prism::SymbolNode) && e.key.value == "via"
|
|
51
|
+
end
|
|
52
|
+
if via_value
|
|
53
|
+
method = via_value.value.unescaped
|
|
54
|
+
replace(node, "#{method} #{source_for(path)}")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Convert scope :name, lambda { } -> scope :name, -> { }
|
|
61
|
+
if @config[:convert_scopes] && match_call?(node, method: :scope)
|
|
62
|
+
args = extract_arguments(node)
|
|
63
|
+
if args.size == 2
|
|
64
|
+
second = args[1]
|
|
65
|
+
if second.is_a?(Prism::CallNode) && match_call?(second, method: :lambda)
|
|
66
|
+
# Already lambda
|
|
67
|
+
elsif second.is_a?(Prism::LambdaNode)
|
|
68
|
+
# Already lambda
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Convert ActiveRecord::Relation#empty? -> .none?
|
|
74
|
+
# This is a runtime change, not syntax
|
|
75
|
+
|
|
76
|
+
super
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 4.0 -> 4.1 syntax upgrades
|
|
10
|
+
class Upgrade40To41 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 4.0 to 4.1"
|
|
12
|
+
description "Converts Rails 4.0 syntax to 4.1: ActionController::Live, config/secrets.yml, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_live, type: [TrueClass, FalseClass], default: true, description: "Convert streaming responses"
|
|
15
|
+
|
|
16
|
+
def get_visitor(context)
|
|
17
|
+
Upgrade40To41Visitor.new(context, config)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class Upgrade40To41Visitor < Reweave::Visitor::RubyVisitor
|
|
22
|
+
def initialize(context, config)
|
|
23
|
+
super(context, nil)
|
|
24
|
+
@config = config
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def run(source_file)
|
|
28
|
+
@source_file = source_file
|
|
29
|
+
traverse(source_file.root)
|
|
30
|
+
edits
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def visit_call_node(node)
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 4.1 -> 4.2 syntax upgrades
|
|
10
|
+
class Upgrade41To42 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 4.1 to 4.2"
|
|
12
|
+
description "Converts Rails 4.1 syntax to 4.2: ActiveJob, AdequateRecord, Web Console, foreign keys, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_activerecord, type: [TrueClass, FalseClass], default: true, description: "Convert ActiveRecord deprecations"
|
|
15
|
+
option :convert_callbacks, type: [TrueClass, FalseClass], default: true, description: "Convert callback syntax"
|
|
16
|
+
|
|
17
|
+
def get_visitor(context)
|
|
18
|
+
Upgrade41To42Visitor.new(context, config)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Upgrade41To42Visitor < Reweave::Visitor::RubyVisitor
|
|
23
|
+
def initialize(context, config)
|
|
24
|
+
super(context, nil)
|
|
25
|
+
@config = config
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run(source_file)
|
|
29
|
+
@source_file = source_file
|
|
30
|
+
traverse(source_file.root)
|
|
31
|
+
edits
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def visit_call_node(node)
|
|
35
|
+
# Convert before_action with string/symbol
|
|
36
|
+
if @config[:convert_callbacks] && match_call?(node, method: :before_action)
|
|
37
|
+
# Already correct
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Convert ActiveRecord::Relation#empty? -> .none?
|
|
41
|
+
super
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 4.2 -> 5.0 syntax upgrades
|
|
10
|
+
class Upgrade42To50 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 4.2 to 5.0"
|
|
12
|
+
description "Converts Rails 4.2 syntax to 5.0: ActionController::Parameters, ActiveRecord::Base belongs_to required, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_controller_params, type: [TrueClass, FalseClass], default: true, description: "Convert params.permit to strong parameters"
|
|
15
|
+
option :convert_belongs_to, type: [TrueClass, FalseClass], default: true, description: "Add optional: true to belongs_to"
|
|
16
|
+
option :convert_before_action, type: [TrueClass, FalseClass], default: true, description: "Convert before_filter to before_action"
|
|
17
|
+
|
|
18
|
+
def get_visitor(context)
|
|
19
|
+
Upgrade42To50Visitor.new(context, config)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Upgrade42To50Visitor < Reweave::Visitor::RubyVisitor
|
|
24
|
+
def initialize(context, config)
|
|
25
|
+
super(context, nil)
|
|
26
|
+
@config = config
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def run(source_file)
|
|
30
|
+
@source_file = source_file
|
|
31
|
+
traverse(source_file.root)
|
|
32
|
+
edits
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def visit_call_node(node)
|
|
36
|
+
# Convert before_filter to before_action
|
|
37
|
+
if @config[:convert_before_action] && match_call?(node, method: :before_filter)
|
|
38
|
+
replace_location(node.message_loc, "before_action")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Convert after_filter to after_action
|
|
42
|
+
if @config[:convert_before_action] && match_call?(node, method: :after_filter)
|
|
43
|
+
replace_location(node.message_loc, "after_action")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Convert skip_before_filter to skip_before_action
|
|
47
|
+
if @config[:convert_before_action] && match_call?(node, method: :skip_before_filter)
|
|
48
|
+
replace_location(node.message_loc, "skip_before_action")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Convert belongs_to without optional
|
|
52
|
+
if @config[:convert_belongs_to] && match_call?(node, method: :belongs_to)
|
|
53
|
+
args = extract_arguments(node)
|
|
54
|
+
if args.size == 1
|
|
55
|
+
# belongs_to :name -> belongs_to :name, optional: true
|
|
56
|
+
replace(node, "#{source_for(node.receiver)}.belongs_to(#{source_for(args[0])}, optional: true)")
|
|
57
|
+
elsif args.size == 2
|
|
58
|
+
second = args[1]
|
|
59
|
+
if second.is_a?(Prism::HashNode)
|
|
60
|
+
has_optional = second.elements.any? do |e|
|
|
61
|
+
e.is_a?(Prism::AssocNode) && e.key.is_a?(Prism::SymbolNode) && e.key.value == "optional"
|
|
62
|
+
end
|
|
63
|
+
unless has_optional
|
|
64
|
+
# Add optional: true
|
|
65
|
+
new_hash = source_for(second).sub(/\}$/, ", optional: true}")
|
|
66
|
+
replace(node, "#{source_for(node.receiver)}.belongs_to(#{source_for(args[0])}, #{new_hash})")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
super
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 5.0 -> 5.1 syntax upgrades
|
|
10
|
+
class Upgrade50To51 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 5.0 to 5.1"
|
|
12
|
+
description "Converts Rails 5.0 syntax to 5.1: form_with, secrets management, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_form_for, type: [TrueClass, FalseClass], default: true, description: "Convert form_for to form_with"
|
|
15
|
+
option :convert_secrets, type: [TrueClass, FalseClass], default: true, description: "Convert secrets.yml to credentials"
|
|
16
|
+
|
|
17
|
+
def get_visitor(context)
|
|
18
|
+
Upgrade50To51Visitor.new(context, config)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Upgrade50To51Visitor < Reweave::Visitor::RubyVisitor
|
|
23
|
+
def initialize(context, config)
|
|
24
|
+
super(context, nil)
|
|
25
|
+
@config = config
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run(source_file)
|
|
29
|
+
@source_file = source_file
|
|
30
|
+
traverse(source_file.root)
|
|
31
|
+
edits
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def visit_call_node(node)
|
|
35
|
+
# Convert form_for to form_with
|
|
36
|
+
if @config[:convert_form_for] && match_call?(node, method: :form_for)
|
|
37
|
+
replace_location(node.message_loc, "form_with")
|
|
38
|
+
# Also need to convert url: to model: or scope:
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Convert secrets to credentials
|
|
42
|
+
if @config[:convert_secrets] && match_call?(node, method: :secrets)
|
|
43
|
+
replace_location(node.message_loc, "credentials")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
super
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../reweave/recipe"
|
|
4
|
+
require_relative "../../../reweave/visitor/ruby_visitor"
|
|
5
|
+
|
|
6
|
+
module Reweave
|
|
7
|
+
module Recipes
|
|
8
|
+
module Rails
|
|
9
|
+
# Rails 5.1 -> 5.2 syntax upgrades
|
|
10
|
+
class Upgrade51To52 < Recipe
|
|
11
|
+
display_name "Upgrade Rails 5.1 to 5.2"
|
|
12
|
+
description "Converts Rails 5.1 syntax to 5.2: ActiveStorage, Redis cache store, etc."
|
|
13
|
+
|
|
14
|
+
option :convert_active_storage, type: [TrueClass, FalseClass], default: true, description: "Convert paperclip/carrierwave to ActiveStorage"
|
|
15
|
+
option :convert_redis_cache, type: [TrueClass, FalseClass], default: true, description: "Convert cache store to Redis"
|
|
16
|
+
|
|
17
|
+
def get_visitor(context)
|
|
18
|
+
Upgrade51To52Visitor.new(context, config)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class Upgrade51To52Visitor < Reweave::Visitor::RubyVisitor
|
|
23
|
+
def initialize(context, config)
|
|
24
|
+
super(context, nil)
|
|
25
|
+
@config = config
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run(source_file)
|
|
29
|
+
@source_file = source_file
|
|
30
|
+
traverse(source_file.root)
|
|
31
|
+
edits
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def visit_call_node(node)
|
|
35
|
+
# Convert Redis cache store
|
|
36
|
+
if @config[:convert_redis_cache] && match_call?(node, method: :cache_store)
|
|
37
|
+
args = extract_arguments(node)
|
|
38
|
+
if args.size >= 1
|
|
39
|
+
first = args[0]
|
|
40
|
+
if first.is_a?(Prism::SymbolNode) && first.value == "redis_store"
|
|
41
|
+
# Already redis
|
|
42
|
+
elsif first.is_a?(Prism::SymbolNode) && first.value == "mem_cache_store"
|
|
43
|
+
# Convert to redis
|
|
44
|
+
replace(node, "config.cache_store = :redis_cache_store")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
super
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|