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
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 21

def header(routes)
  @parlour.root.add_comments([
    '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_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



41
42
43
44
45
46
47
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 41

def no_routes(routes = nil, filter = nil)
  @parlour.root.add_comments([
    '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



50
51
52
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 50

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