reweave 0.1.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +202 -0
- data/bin/reweave +200 -0
- data/lib/reweave/config.rb +119 -0
- data/lib/reweave/discovery/file_discoverer.rb +23 -0
- data/lib/reweave/editing/edit.rb +52 -0
- data/lib/reweave/editing/edit_set.rb +96 -0
- data/lib/reweave/editing/editor.rb +53 -0
- data/lib/reweave/editing.rb +23 -0
- data/lib/reweave/execution/engine.rb +317 -0
- data/lib/reweave/execution/execution_context.rb +87 -0
- data/lib/reweave/execution/project.rb +45 -0
- data/lib/reweave/execution.rb +10 -0
- data/lib/reweave/parser.rb +71 -0
- data/lib/reweave/recipe/composite_recipe.rb +26 -0
- data/lib/reweave/recipe/recipe.rb +118 -0
- data/lib/reweave/recipe/recipe_descriptor.rb +35 -0
- data/lib/reweave/recipe/recipe_option.rb +46 -0
- data/lib/reweave/recipe/recipe_registry.rb +44 -0
- data/lib/reweave/recipe/scanning_recipe.rb +29 -0
- data/lib/reweave/recipe/validation_error.rb +5 -0
- data/lib/reweave/recipe.rb +11 -0
- data/lib/reweave/recipes/rails/active_job_continuations.rb +62 -0
- data/lib/reweave/recipes/rails/controller_markdown_rendering.rb +48 -0
- data/lib/reweave/recipes/rails/remove_deprecated_gems.rb +71 -0
- data/lib/reweave/recipes/rails/replace_deprecated_find.rb +63 -0
- data/lib/reweave/recipes/rails/solid_cache_migration.rb +60 -0
- data/lib/reweave/recipes/rails/solid_queue_migration.rb +52 -0
- data/lib/reweave/recipes/rails/update_active_record.rb +70 -0
- data/lib/reweave/recipes/rails/update_configuration.rb +59 -0
- data/lib/reweave/recipes/rails/update_rails_routes.rb +51 -0
- data/lib/reweave/recipes/rails/upgrade_rails.rb +39 -0
- data/lib/reweave/recipes/ruby/find_method_calls.rb +72 -0
- data/lib/reweave/recipes/ruby/modernize_syntax.rb +81 -0
- data/lib/reweave/recipes/ruby/remove_unused_methods.rb +93 -0
- data/lib/reweave/recipes/ruby/rename_method.rb +55 -0
- data/lib/reweave/results/changeset.rb +96 -0
- data/lib/reweave/results/execution_result.rb +104 -0
- data/lib/reweave/results.rb +9 -0
- data/lib/reweave/source.rb +92 -0
- data/lib/reweave/version.rb +5 -0
- data/lib/reweave/visitor/cursor.rb +105 -0
- data/lib/reweave/visitor/ruby_visitor.rb +397 -0
- data/lib/reweave/visitor/visitor.rb +127 -0
- data/lib/reweave/visitor.rb +10 -0
- data/lib/reweave.rb +27 -0
- metadata +164 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "recipe"
|
|
4
|
+
|
|
5
|
+
module Reweave
|
|
6
|
+
class CompositeRecipe < Recipe
|
|
7
|
+
def initialize(recipes = [], **kwargs)
|
|
8
|
+
@recipes = recipes
|
|
9
|
+
super(**kwargs)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def recipe_list
|
|
13
|
+
@recipes
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
attr_reader :recipes
|
|
17
|
+
|
|
18
|
+
def ==(other)
|
|
19
|
+
super && other.recipes == @recipes
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def hash
|
|
23
|
+
[super, @recipes].hash
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "recipe_option"
|
|
4
|
+
require_relative "recipe_descriptor"
|
|
5
|
+
require_relative "validation_error"
|
|
6
|
+
|
|
7
|
+
module Reweave
|
|
8
|
+
class Recipe
|
|
9
|
+
class << self
|
|
10
|
+
def display_name(name = nil)
|
|
11
|
+
if name
|
|
12
|
+
@display_name = name
|
|
13
|
+
else
|
|
14
|
+
@display_name ||= name_from_class
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def description(text = nil)
|
|
19
|
+
if text
|
|
20
|
+
@description = text
|
|
21
|
+
else
|
|
22
|
+
@description
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def option(name, type:, required: false, default: nil, description: nil, &block)
|
|
27
|
+
@options ||= {}
|
|
28
|
+
@options[name] = RecipeOption.new(name, type: type, required: required, default: default, description: description, &block)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def options
|
|
32
|
+
@options ||= {}
|
|
33
|
+
inherited_options = superclass.respond_to?(:options) ? superclass.options : {}
|
|
34
|
+
inherited_options.merge(@options)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def name_from_class
|
|
38
|
+
name.split("::").last.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def inherited(subclass)
|
|
42
|
+
subclass.instance_variable_set(:@options, options.dup) if @options
|
|
43
|
+
# Auto-register concrete recipe classes (not abstract base classes)
|
|
44
|
+
if subclass != Reweave::Recipe && subclass != Reweave::CompositeRecipe && subclass != Reweave::ScanningRecipe
|
|
45
|
+
Reweave::REGISTRY.register(subclass)
|
|
46
|
+
end
|
|
47
|
+
super
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
attr_reader :config, :options
|
|
52
|
+
|
|
53
|
+
def initialize(**kwargs)
|
|
54
|
+
@config = self.class.options.transform_values { |opt| opt.default }
|
|
55
|
+
@options = kwargs
|
|
56
|
+
|
|
57
|
+
validate_options!
|
|
58
|
+
@config.merge!(@options)
|
|
59
|
+
freeze
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def display_name
|
|
63
|
+
self.class.display_name
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def description
|
|
67
|
+
self.class.description
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def descriptor
|
|
71
|
+
RecipeDescriptor.new(self)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def recipe_list
|
|
75
|
+
[]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def get_visitor(context)
|
|
79
|
+
nil
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def scanning_recipe?
|
|
83
|
+
false
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def validate
|
|
87
|
+
[]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def ==(other)
|
|
91
|
+
other.is_a?(self.class) && other.config == @config
|
|
92
|
+
end
|
|
93
|
+
alias_method :eql?, :==
|
|
94
|
+
|
|
95
|
+
def hash
|
|
96
|
+
[self.class, @config].hash
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
def validate_options!
|
|
102
|
+
self.class.options.each do |name, option|
|
|
103
|
+
value = @options[name]
|
|
104
|
+
if option.required? && (value.nil? || (value.respond_to?(:empty?) && value.empty?))
|
|
105
|
+
raise ValidationError, "Required option '#{name}' not provided for #{self.class.display_name}"
|
|
106
|
+
end
|
|
107
|
+
if value && !option.valid?(value)
|
|
108
|
+
raise ValidationError, "Invalid value for option '#{name}': #{option.validate_message(value)}"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
unknown = @options.keys - self.class.options.keys
|
|
113
|
+
unless unknown.empty?
|
|
114
|
+
raise ValidationError, "Unknown options: #{unknown.join(", ")}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Reweave
|
|
4
|
+
class RecipeDescriptor
|
|
5
|
+
attr_reader :recipe_class, :display_name, :description, :options
|
|
6
|
+
|
|
7
|
+
def initialize(recipe)
|
|
8
|
+
@recipe_class = recipe.class
|
|
9
|
+
@display_name = recipe.display_name
|
|
10
|
+
@description = recipe.description
|
|
11
|
+
@options = recipe.class.options.transform_values do |opt|
|
|
12
|
+
{
|
|
13
|
+
type: opt.type,
|
|
14
|
+
required: opt.required?,
|
|
15
|
+
default: opt.default,
|
|
16
|
+
description: opt.description
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_h
|
|
22
|
+
{
|
|
23
|
+
name: @recipe_class.name,
|
|
24
|
+
display_name: @display_name,
|
|
25
|
+
description: @description,
|
|
26
|
+
options: @options
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def to_yaml
|
|
31
|
+
require "yaml"
|
|
32
|
+
to_h.to_yaml
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Reweave
|
|
4
|
+
class RecipeOption
|
|
5
|
+
attr_reader :name, :type, :required, :default, :description, :validator
|
|
6
|
+
|
|
7
|
+
def initialize(name, type:, required: false, default: nil, description: nil, &block)
|
|
8
|
+
@name = name
|
|
9
|
+
@type = type
|
|
10
|
+
@required = required
|
|
11
|
+
@default = default
|
|
12
|
+
@description = description
|
|
13
|
+
@validator = block
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def required?
|
|
17
|
+
@required
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def valid?(value)
|
|
21
|
+
return false unless type_match?(value)
|
|
22
|
+
return true unless @validator
|
|
23
|
+
@validator.call(value)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def validate_message(value)
|
|
27
|
+
unless type_match?(value)
|
|
28
|
+
return "expected #{@type}, got #{value.class}"
|
|
29
|
+
end
|
|
30
|
+
"validation failed" if @validator && !@validator.call(value)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def type_match?(value)
|
|
36
|
+
case @type
|
|
37
|
+
when Class, Module
|
|
38
|
+
value.is_a?(@type)
|
|
39
|
+
when Array
|
|
40
|
+
value.is_a?(Array) && value.all? { |v| type_match?(v) }
|
|
41
|
+
else
|
|
42
|
+
true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "recipe"
|
|
4
|
+
|
|
5
|
+
module Reweave
|
|
6
|
+
class RecipeRegistry
|
|
7
|
+
def initialize
|
|
8
|
+
@recipes = {}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def register(recipe_class, name: nil)
|
|
12
|
+
name ||= recipe_class.name
|
|
13
|
+
@recipes[name] = recipe_class
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get(name)
|
|
17
|
+
@recipes[name] || @recipes.values.find { |r| r.name.split("::").last == name }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def all
|
|
21
|
+
@recipes.values
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def names
|
|
25
|
+
@recipes.keys
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def find_by_display_name(display_name)
|
|
29
|
+
@recipes.values.find { |r| r.display_name == display_name }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Auto-discover and load recipes from a directory
|
|
33
|
+
def discover_recipes(path = nil)
|
|
34
|
+
path ||= File.join(File.dirname(__FILE__), "..", "..", "..", "lib", "reweave", "recipes")
|
|
35
|
+
return unless Dir.exist?(path)
|
|
36
|
+
|
|
37
|
+
Dir.glob(File.join(path, "**", "*.rb")).each do |file|
|
|
38
|
+
require file
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
REGISTRY = RecipeRegistry.new
|
|
44
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "recipe"
|
|
4
|
+
|
|
5
|
+
module Reweave
|
|
6
|
+
class ScanningRecipe < Recipe
|
|
7
|
+
def scanning_recipe?
|
|
8
|
+
true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initial_accumulator
|
|
12
|
+
{}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def scan(source_file, accumulator, context)
|
|
16
|
+
# Override in subclass
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def generate(accumulator, project)
|
|
20
|
+
# Override to generate files from accumulated data
|
|
21
|
+
[]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get_visitor(accumulator, context)
|
|
25
|
+
# Override to return a visitor that uses accumulated data
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "recipe/recipe"
|
|
4
|
+
require_relative "recipe/recipe_option"
|
|
5
|
+
require_relative "recipe/recipe_descriptor"
|
|
6
|
+
require_relative "recipe/validation_error"
|
|
7
|
+
require_relative "recipe/composite_recipe"
|
|
8
|
+
require_relative "recipe/scanning_recipe"
|
|
9
|
+
require_relative "recipe/recipe_registry"
|
|
10
|
+
|
|
11
|
+
# Recipe is a class, not a module - the submodules are accessed via Reweave::Recipe::<ClassName>
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
# Inject stopping? checks for ActiveJob continuations
|
|
10
|
+
class ActiveJobContinuations < Recipe
|
|
11
|
+
display_name "ActiveJob continuations"
|
|
12
|
+
description "Injects stopping? checks in ActiveJob perform methods for SolidQueue"
|
|
13
|
+
|
|
14
|
+
def get_visitor(context)
|
|
15
|
+
ActiveJobContinuationsVisitor.new(context)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class ActiveJobContinuationsVisitor < Reweave::Visitor::RubyVisitor
|
|
20
|
+
def initialize(context, **)
|
|
21
|
+
super(context, nil)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run(source_file)
|
|
25
|
+
@source_file = source_file
|
|
26
|
+
traverse(source_file.root)
|
|
27
|
+
edits
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def visit_def_node(node)
|
|
31
|
+
# Check if this is a perform method in an ActiveJob class
|
|
32
|
+
return super unless node.name == :perform
|
|
33
|
+
|
|
34
|
+
# Check if parent is a class that inherits from ApplicationJob or ActiveJob::Base
|
|
35
|
+
cursor = self.cursor
|
|
36
|
+
if cursor
|
|
37
|
+
ancestors = cursor.ancestors
|
|
38
|
+
is_job_class = ancestors.any? do |ancestor|
|
|
39
|
+
ancestor.node.is_a?(Prism::ClassNode) &&
|
|
40
|
+
ancestor.node.superclass&.slice&.include?("ApplicationJob") ||
|
|
41
|
+
ancestor.node.superclass&.slice&.include?("ActiveJob::Base")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if is_job_class
|
|
45
|
+
# Add stopping? check at the beginning of the method
|
|
46
|
+
body = node.body
|
|
47
|
+
if body&.is_a?(Prism::StatementsNode) && body.body&.any?
|
|
48
|
+
first_stmt = body.body.first
|
|
49
|
+
insert_before(first_stmt, "return if stopping?\n ")
|
|
50
|
+
elsif body&.is_a?(Prism::StatementsNode) && body.body&.empty?
|
|
51
|
+
# Empty method, add the check
|
|
52
|
+
insert_after(node.opening_loc || node.name_loc, "\n return if stopping?")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
super
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
# Replace render markdown: with native Rails 8 render markdown:
|
|
10
|
+
class ControllerMarkdownRendering < Recipe
|
|
11
|
+
display_name "Controller markdown rendering"
|
|
12
|
+
description "Replaces render markdown: with native Rails 8 render markdown:"
|
|
13
|
+
|
|
14
|
+
def get_visitor(context)
|
|
15
|
+
ControllerMarkdownRenderingVisitor.new(context)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class ControllerMarkdownRenderingVisitor < Reweave::Visitor::RubyVisitor
|
|
20
|
+
def initialize(context, **)
|
|
21
|
+
super(context, nil)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run(source_file)
|
|
25
|
+
@source_file = source_file
|
|
26
|
+
traverse(source_file.root)
|
|
27
|
+
edits
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def visit_call_node(node)
|
|
31
|
+
# render markdown: "content" -> render markdown: "content" (already correct in Rails 8)
|
|
32
|
+
# render inline: "...", type: :markdown -> render markdown: "..."
|
|
33
|
+
if match_call?(node, method: :render)
|
|
34
|
+
kwargs = extract_keyword_arguments(node)
|
|
35
|
+
if kwargs[:type]&.is_a?(Prism::SymbolNode) && kwargs[:type].value == :markdown
|
|
36
|
+
if kwargs[:inline]
|
|
37
|
+
# Replace render inline: "...", type: :markdown with render markdown: "..."
|
|
38
|
+
replace(node, "render markdown: #{kwargs[:inline].slice}")
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
super
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
# Remove gems that are now built into Rails
|
|
10
|
+
class RemoveDeprecatedGems < Recipe
|
|
11
|
+
display_name "Remove deprecated gems"
|
|
12
|
+
description "Removes gems that have been replaced by Rails built-ins (e.g., spring, listen, web-console)"
|
|
13
|
+
|
|
14
|
+
DEPRECATED_GEMS = %w[
|
|
15
|
+
spring
|
|
16
|
+
listen
|
|
17
|
+
web-console
|
|
18
|
+
byebug
|
|
19
|
+
capistrano
|
|
20
|
+
capistrano-rails
|
|
21
|
+
capistrano-bundler
|
|
22
|
+
capistrano-rvm
|
|
23
|
+
capistrano-passenger
|
|
24
|
+
].freeze
|
|
25
|
+
|
|
26
|
+
def get_visitor(context)
|
|
27
|
+
RemoveDeprecatedGemsVisitor.new(context)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class RemoveDeprecatedGemsVisitor < Reweave::Visitor::RubyVisitor
|
|
32
|
+
def initialize(context, **)
|
|
33
|
+
super(context, nil)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def run(source_file)
|
|
37
|
+
@source_file = source_file
|
|
38
|
+
traverse(source_file.root)
|
|
39
|
+
edits
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def visit_call_node(node)
|
|
43
|
+
# Match gem 'spring' in Gemfile
|
|
44
|
+
if node.name == :gem
|
|
45
|
+
args = extract_arguments(node)
|
|
46
|
+
if args.first&.is_a?(Prism::StringNode)
|
|
47
|
+
gem_name = args.first.value
|
|
48
|
+
if RemoveDeprecatedGems::DEPRECATED_GEMS.include?(gem_name)
|
|
49
|
+
# Delete the entire gem line
|
|
50
|
+
delete(node)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Match gem 'spring', group: :development
|
|
56
|
+
if node.name == :gem
|
|
57
|
+
args = extract_arguments(node)
|
|
58
|
+
if args.first&.is_a?(Prism::StringNode)
|
|
59
|
+
gem_name = args.first.value
|
|
60
|
+
if RemoveDeprecatedGems::DEPRECATED_GEMS.include?(gem_name)
|
|
61
|
+
delete(node)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
super
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
# Replace deprecated Model.find(:all), Model.find(:first), Model.find(:last)
|
|
10
|
+
class ReplaceDeprecatedFind < Recipe
|
|
11
|
+
display_name "Replace deprecated find"
|
|
12
|
+
description "Replaces deprecated ActiveRecord find(:all), find(:first), find(:last) with all, first, last"
|
|
13
|
+
|
|
14
|
+
option :include_find_by, type: [TrueClass, FalseClass], default: true, description: "Also replace find_by_* dynamic finders"
|
|
15
|
+
|
|
16
|
+
def get_visitor(context)
|
|
17
|
+
ReplaceDeprecatedFindVisitor.new(context, include_find_by: config[:include_find_by])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class ReplaceDeprecatedFindVisitor < Reweave::Visitor::RubyVisitor
|
|
22
|
+
def initialize(context, include_find_by: true)
|
|
23
|
+
super(context, nil)
|
|
24
|
+
@include_find_by = include_find_by
|
|
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
|
+
return super unless node.receiver
|
|
35
|
+
|
|
36
|
+
# Match Model.find(:all) -> Model.all
|
|
37
|
+
if match_call?(node, method: :find)
|
|
38
|
+
args = extract_arguments(node)
|
|
39
|
+
if args.size == 1 && args.first.is_a?(Prism::SymbolNode)
|
|
40
|
+
receiver = extract_receiver_name(node)
|
|
41
|
+
case args.first.value
|
|
42
|
+
when "all"
|
|
43
|
+
replace(node, receiver + ".all")
|
|
44
|
+
when "first"
|
|
45
|
+
replace(node, receiver + ".first")
|
|
46
|
+
when "last"
|
|
47
|
+
replace(node, receiver + ".last")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Match dynamic finders like find_by_name_and_email
|
|
53
|
+
if @include_find_by && node.name.to_s.start_with?("find_by_")
|
|
54
|
+
# Could convert to where(name: ..., email: ...).first
|
|
55
|
+
# For now just note it
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
super
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
# Migrate cache store to SolidCache
|
|
10
|
+
class SolidCacheMigration < Recipe
|
|
11
|
+
display_name "SolidCache migration"
|
|
12
|
+
description "Migrates cache store configuration to SolidCache"
|
|
13
|
+
|
|
14
|
+
def get_visitor(context)
|
|
15
|
+
SolidCacheMigrationVisitor.new(context)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class SolidCacheMigrationVisitor < Reweave::Visitor::RubyVisitor
|
|
20
|
+
def initialize(context, **)
|
|
21
|
+
super(context, nil)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run(source_file)
|
|
25
|
+
@source_file = source_file
|
|
26
|
+
traverse(source_file.root)
|
|
27
|
+
edits
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def visit_call_node(node)
|
|
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
|
+
# 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
|
+
# config.cache_store = :memory_store -> :solid_cache_store
|
|
48
|
+
if match_call?(node, receiver: "config", method: :cache_store=)
|
|
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
|
|
54
|
+
|
|
55
|
+
super
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
# Migrate ActiveJob queue adapter to SolidQueue
|
|
10
|
+
class SolidQueueMigration < Recipe
|
|
11
|
+
display_name "SolidQueue migration"
|
|
12
|
+
description "Migrates ActiveJob queue adapter configuration to SolidQueue"
|
|
13
|
+
|
|
14
|
+
def get_visitor(context)
|
|
15
|
+
SolidQueueMigrationVisitor.new(context)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class SolidQueueMigrationVisitor < Reweave::Visitor::RubyVisitor
|
|
20
|
+
def initialize(context, **)
|
|
21
|
+
super(context, nil)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run(source_file)
|
|
25
|
+
@source_file = source_file
|
|
26
|
+
traverse(source_file.root)
|
|
27
|
+
edits
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def visit_call_node(node)
|
|
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
|
+
# config.active_job.queue_adapter = "sidekiq" -> "solid_queue"
|
|
40
|
+
if match_call?(node, receiver: "config.active_job", method: :queue_adapter=)
|
|
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
|
|
46
|
+
|
|
47
|
+
super
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|