Class: SorbetRails::RoutesRbiFormatter

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/sorbet-rails/routes_rbi_formatter.rb

Overview

typed: strict

Instance Method Summary collapse

Constructor Details

#initializeRoutesRbiFormatter

Returns a new instance of RoutesRbiFormatter.


6
7
8
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 6

def initialize
  @parlour = T.let(Parlour::RbiGenerator.new, Parlour::RbiGenerator)
end

Instance Method Details

#header(routes) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 21

def header(routes)
  @parlour.root.add_comment([
    'This is an autogenerated file for Rails routes.',
    'Please run bundle exec rake rails_rbi:routes to regenerate.'
  ])

  @parlour.root.create_class('ActionController::Base') do |klass|
    klass.create_include('GeneratedUrlHelpers')
  end

  @parlour.root.create_class('ActionController::API') do |klass|
    klass.create_include('GeneratedUrlHelpers')
  end

  @parlour.root.create_module('ActionView::Helpers') do |mod|
    mod.create_include('GeneratedUrlHelpers')
  end

  @parlour.root.create_class('ActionMailer::Base') do |mod|
    mod.create_include('GeneratedUrlHelpers')
  end
end

#no_routes(routes = nil, filter = nil) ⇒ Object


45
46
47
48
49
50
51
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 45

def no_routes(routes = nil, filter = nil)
  @parlour.root.add_comment([
    'You do not have any routes defined!',
    'Please add some routes in config/routes.rb.',
    'For more information about routes, see the Rails guide: https://guides.rubyonrails.org/routing.html.'
  ])
end

#resultObject


54
55
56
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 54

def result
  @parlour.rbi
end

#section(routes) ⇒ Object


16
17
18
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 16

def section(routes)
  draw_section(routes)
end

#section_title(title) ⇒ Object


11
12
13
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 11

def section_title(title)
  nil
end