Module: LogStruct::RailsBootBannerSilencer

Extended by:
T::Sig
Defined in:
lib/log_struct/rails_boot_banner_silencer.rb

Defined Under Namespace

Modules: ServerCommandSilencer

Class Method Summary collapse

Class Method Details

.install! ⇒ void

This method returns an undefined value.



13
14
15
16
17
18
19
20
21
22
# File 'lib/log_struct/rails_boot_banner_silencer.rb', line 13

def self.install!
  return if @installed
  @installed = true

  return unless ARGV.include?("server")
  # Rails' own banner stays when LogStruct is disabled
  return unless LogStruct.enabled?

  patch!
end

.patch! ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/log_struct/rails_boot_banner_silencer.rb', line 25

def self.patch!
  begin
    require "rails/command"
    require "rails/commands/server/server_command"
  rescue LoadError
    # Best-effort – if Rails isn't available yet we'll try again later
    return false
  end

  server_command = T.let(nil, T.untyped)
  # rubocop:disable Sorbet/ConstantsFromStrings
  begin
    server_command = ::Object.const_get("Rails::Command::ServerCommand")
  rescue NameError
    server_command = nil
  end
  # rubocop:enable Sorbet/ConstantsFromStrings
  return false unless server_command

  patch_server_command(server_command)
  true
end

.patch_server_command(server_command) ⇒ void

This method returns an undefined value.

Parameters:

  • server_command (T.untyped)


49
50
51
52
53
# File 'lib/log_struct/rails_boot_banner_silencer.rb', line 49

def self.patch_server_command(server_command)
  return if server_command <= ServerCommandSilencer

  server_command.prepend(ServerCommandSilencer)
end