Class: NitroKit::MigrationInventory

Inherits:
Object
  • Object
show all
Defined in:
lib/nitro_kit/migration_inventory.rb

Defined Under Namespace

Classes: Finding

Constant Summary collapse

LEGACY_COMPONENTS =
%w[
  accordion alert avatar avatar_stack badge button button_group card checkbox
  checkbox_group combobox component datepicker dialog dropdown field field_group
  fieldset form_builder icon input label pagination radio_button radio_button_group
  select switch table tabs textarea toast tooltip
].freeze
LEGACY_CONTROLLERS =
%w[
  accordion combobox datepicker dialog dropdown switch tabs toast tooltip
].freeze
HELPER_REPLACEMENTS =
{
  "nk_button_link_to" => "replace with Button(..., href:)",
  "nk_button_to" => "replace with ButtonTo(..., href:, method:)",
  "nk_form_with" => "replace with Rails form_with(..., builder: NitroKit::FormBuilder)",
  "nk_form_for" => "replace with Rails form_with(..., builder: NitroKit::FormBuilder)",
  "nk_pagy_nav" => "replace with Pagination(pagy:)",
  "nk_toast_flash_messages" => "replace with NitroKit::Toast::FlashMessages",
  "nk_toast_turbo_stream_refresh" => "append NitroKit::Toast::Item to the toast list",
  "nk_toast_action" => "replace the client toast action with Rails flash or a rendered Toast::Item",
  "nk_checkbox_tag" => "replace with Checkbox(...) and preserve the submitted name and values",
  "nk_check_box_tag" => "replace with Checkbox(...) and preserve the submitted name and values"
}.freeze
DIRECT_HELPERS =
(LEGACY_COMPONENTS - %w[component datepicker form_builder]).freeze
FIELD_TAG_REPLACEMENTS =
{
  "color" => :color,
  "date" => :date,
  "datetime" => :"datetime-local",
  "datetime_local" => :"datetime-local",
  "email" => :email,
  "file" => :file,
  "hidden" => :hidden,
  "month" => :month,
  "number" => :number,
  "password" => :password,
  "phone" => :tel,
  "range" => :range,
  "search" => :search,
  "telephone" => :tel,
  "text" => :text,
  "time" => :time,
  "url" => :url,
  "week" => :week
}.transform_keys { "nk_#{_1}_field_tag" }.freeze
VENDORED_MODULES =
{
  "@floating-ui/core" => "remove the 1.x Floating UI pin or package after copied controllers are removed",
  "@floating-ui/dom" => "remove the 1.x Floating UI pin or package after copied controllers are removed",
  "@floating-ui/utils" => "remove the 1.x Floating UI pin or package after copied controllers are removed",
  "@github/combobox-nav" => "remove the 1.x combobox package; Nitro Kit 2 owns combobox behavior"
}.freeze
BUTTON_TREATMENT_DEFINITION =
/@utility\s+btn\b|\.btn(?:\s|[,{.:])/.freeze
BUTTON_CLASS =
/(?<![a-z0-9_-])btn(?:-[a-z0-9_-]+)?(?![a-z0-9_-])/i.freeze
ERB_TAG_PATTERN =
/<%(?!%|#)(==|[-=])?(.*?)(?:-)?%>/m
TABLE_COMPOUND_KEYWORDS =
{
  caption: %i[html aria data desperately_need_a_class],
  thead: %i[html aria data desperately_need_a_class],
  tbody: %i[html aria data desperately_need_a_class],
  tr: %i[html aria data desperately_need_a_class],
  th: %i[align scope sort href sort_data html aria data desperately_need_a_class],
  td: %i[align html aria data desperately_need_a_class]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_root) ⇒ MigrationInventory

Returns a new instance of MigrationInventory.



234
235
236
# File 'lib/nitro_kit/migration_inventory.rb', line 234

def initialize(application_root)
  @application_root = Pathname.new(application_root)
end

Instance Attribute Details

#application_rootObject (readonly)

Returns the value of attribute application_root.



232
233
234
# File 'lib/nitro_kit/migration_inventory.rb', line 232

def application_root
  @application_root
end

Instance Method Details

#categoriesObject



238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/nitro_kit/migration_inventory.rb', line 238

def categories
  {
    "Legacy helpers" => legacy_helpers,
    "Copied or shadow components" => copied_components,
    "Custom or legacy controllers" => controllers,
    "Vendored dependencies" => vendored_dependencies,
    "Application-owned button treatments" => application_button_treatments,
    "2.0 runtime contract errors" => runtime_contract_errors,
    "Known replacements" => replacement_summary,
    "Unresolved or application-owned items" => disposition_summary
  }
end