Module: SorbetRails::Utils

Extended by:
T::Sig
Defined in:
lib/sorbet-rails/utils.rb

Overview

typed: false

Class Method Summary collapse

Class Method Details

.rails_eager_load_all!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sorbet-rails/utils.rb', line 7

def self.rails_eager_load_all!
  # need to eager load to see all models
  Rails.configuration.eager_load_namespaces.each { |ns| ns.try(:eager_load!) }
  # Rails 6.0 change the loading logic to use Zeitwerk
  # https://github.com/rails/rails/blob/master/railties/lib/rails/application/finisher.rb#L116
  # But this is not applied to Rails.application.eager_load! method
  Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk)
  # Let's eager_load more stuff so that we have the full picture of the runtime environment.
  # Also only applicable to Rails 6.
  if Rails.respond_to?(:autoloaders)
    Rails.autoloaders.each(&:eager_load)
  end
end

.valid_method_name?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/sorbet-rails/utils.rb', line 22

def self.valid_method_name?(method_name)
  !!method_name.match(/^[A-z][A-z0-9_]*[!?=]?$/)
end