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
  @buffer = T.let([], T::Array[T.any(String, T::Array[String])])
end

Instance Method Details

#header(routes) ⇒ Object



21
22
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 21

def header(routes)
end

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



25
26
27
28
29
30
31
32
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 25

def no_routes(routes=nil, filter=nil)
  @buffer <<
    <<~MESSAGE
      # 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.
    MESSAGE
end

#resultObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sorbet-rails/routes_rbi_formatter.rb', line 35

def result
  <<~MESSAGE
    # This is an autogenerated file for routes helper methods

    # typed: strong
    class ActionController::Base
      extend T::Sig

    #{@buffer.join("\n").indent(2)}
    end
  MESSAGE
end

#section(routes) ⇒ Object



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

def section(routes)
  @buffer << 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)
  @buffer << "\n# Section #{title}"
end