Class: RubyUIConverter::Doctor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_ui_converter/doctor.rb

Overview

Post-conversion diagnostics: inspects the target app (the nearest Gemfile at or above the converted path) for the prerequisites the generated code needs — phlex-rails, the ruby_ui gem + generated components and, with –literal, the literal gem + Literal::Properties on the base class.

The Doctor only diagnoses; executing the fix commands (and prompting the user) is the CLI’s responsibility. Commands starting with “#” are manual hints, not executable; issues may also carry a ‘fixer` proc that applies a file edit (e.g. inserting `extend Literal::Properties`).

Defined Under Namespace

Classes: Issue

Constant Summary collapse

COMPONENT_FAMILIES =

Emitted kit component -> ‘ruby_ui:component` generator family.

{
  "Link" => "Link", "Button" => "Button", "Input" => "Input",
  "Checkbox" => "Checkbox", "RadioButton" => "RadioButton",
  "Textarea" => "Textarea",
  "NativeSelect" => "NativeSelect", "NativeSelectOption" => "NativeSelect",
  "Table" => "Table", "TableHeader" => "Table", "TableBody" => "Table",
  "TableFooter" => "Table", "TableRow" => "Table", "TableHead" => "Table",
  "TableCell" => "Table", "TableCaption" => "Table",
  "Separator" => "Separator", "Badge" => "Badge", "Card" => "Card",
  "FormField" => "Form", "FormFieldLabel" => "Form",
  "FormFieldError" => "Form", "FormFieldHint" => "Form",
  "Alert" => "Alert", "AlertTitle" => "Alert", "AlertDescription" => "Alert"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(results, config:, start_path:) ⇒ Doctor

Returns a new instance of Doctor.



31
32
33
34
35
# File 'lib/ruby_ui_converter/doctor.rb', line 31

def initialize(results, config:, start_path:)
  @results = results
  @config = config
  @start_path = File.expand_path(start_path)
end

Instance Method Details

#app_rootObject

The nearest directory at or above start_path containing a Gemfile. nil when the converted path is not inside a bundled app.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby_ui_converter/doctor.rb', line 39

def app_root
  return @app_root if defined?(@app_root)

  dir = File.directory?(@start_path) ? @start_path : File.dirname(@start_path)
  @app_root = loop do
    break dir if File.exist?(File.join(dir, "Gemfile"))

    parent = File.dirname(dir)
    break nil if parent == dir

    dir = parent
  end
end

#issuesObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby_ui_converter/doctor.rb', line 53

def issues
  return [] unless app_root

  [
    phlex_rails_issue,
    literal_gem_issue,
    literal_properties_issue,
    ruby_ui_gem_issue,
    missing_components_issue,
    tw_animate_issue
  ].compact
end