Class: Polaris::ViewComponents::Codemods::V3SlotSetters

Inherits:
Object
  • Object
show all
Defined in:
lib/polaris/view_components/codemods/v3_slot_setters.rb

Defined Under Namespace

Classes: Suggestion

Constant Summary collapse

TEMPLATE_LANGUAGES =
%w[erb slim haml].join(",").freeze
RENDER_REGEX =

standard:disable Lint/MixedRegexpCaptureTypes

/render[( ](?<component>\w+(?:::\w+)*)\.new[) ]+(do|\{) \|(?<arg>\w+)\b/

Instance Method Summary collapse

Constructor Details

#initialize(view_component_path: [], view_path: [], migrate: false) ⇒ V3SlotSetters

Returns a new instance of V3SlotSetters.



25
26
27
28
29
30
31
# File 'lib/polaris/view_components/codemods/v3_slot_setters.rb', line 25

def initialize(view_component_path: [], view_path: [], migrate: false)
  Rails.application.eager_load!

  @view_component_path = view_component_path
  @view_path = view_path
  @migrate = migrate
end

Instance Method Details

#callObject



33
34
35
36
37
38
39
40
41
# File 'lib/polaris/view_components/codemods/v3_slot_setters.rb', line 33

def call
  puts "Using ViewComponent path: #{view_component_paths.join(", ")}"
  puts "Using Views path: #{view_paths.join(", ")}"
  puts "#{view_components.size} ViewComponents found"
  puts "#{slottable_components.size} ViewComponents using Slots found"
  puts "#{view_component_files.size} ViewComponent templates found"
  puts "#{view_files.size} view files found"
  process_all_files
end

#process_all_filesObject



43
44
45
46
47
# File 'lib/polaris/view_components/codemods/v3_slot_setters.rb', line 43

def process_all_files
  all_files.each do |file|
    process_file(file)
  end
end

#process_file(file) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/polaris/view_components/codemods/v3_slot_setters.rb', line 49

def process_file(file)
  @suggestions = []
  @suggestions += scan_exact_matches(file)
  @suggestions += scan_uncertain_matches(file)

  if @suggestions.any?
    puts
    puts "File: #{file}"
    @suggestions.each do |s|
      puts "=> line #{s.line}: #{s.message}"
    end
  end
end