Class: JsxRosetta::Backend::RoutesScript

Inherits:
Object
  • Object
show all
Defined in:
lib/jsx_rosetta/backend/routes_script.rb

Overview

Emits a reviewable Ruby script from an IR::RouteTree.

The output prints the parsed routes, lists ‘system “rails”, “generate”, “controller”, …` invocations (commented out by default), and a suggested config/routes.rb block. The user is expected to review the script, uncomment the commands they want to run, and execute it with `ruby <output>.rb`.

Constant Summary collapse

RESERVED_CONTROLLER_NAMES =
%w[application action rails].freeze

Instance Method Summary collapse

Constructor Details

#initialize(source_path: nil, generated_at: Time.now.utc.strftime("%Y-%m-%d")) ⇒ RoutesScript

Returns a new instance of RoutesScript.



17
18
19
20
# File 'lib/jsx_rosetta/backend/routes_script.rb', line 17

def initialize(source_path: nil, generated_at: Time.now.utc.strftime("%Y-%m-%d"))
  @source_path = source_path
  @generated_at = generated_at
end

Instance Method Details

#emit(route_tree) ⇒ Object



22
23
24
25
# File 'lib/jsx_rosetta/backend/routes_script.rb', line 22

def emit(route_tree)
  lines = header_lines + body_lines(route_tree)
  "#{lines.join("\n")}\n"
end