Sha256: 46039c9752b0cabd4ae629e2fd52744e0e42de3cc2137895b4efbdd4d8c7f48c

Contents?: true

Size: 1.11 KB

Versions: 90

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true
# typed: true

# Used in `sig.checked(level)` to determine when runtime type checking
# is enabled on a method.
module T::Private::RuntimeLevels
  LEVELS = [
    # Validate every call in every environment
    :always,
    # Validate in tests, but not in production
    :tests,
    # Don't even validate in tests, b/c too expensive,
    # or b/c we fully trust the static typing
    :never,
  ].freeze

  @check_tests = false
  @wrapped_tests_with_validation = false

  def self.check_tests?
    # Assume that this code path means that some `sig.checked(:tests)`
    # has been wrapped (or not wrapped) already, which is a trapdoor
    # for toggling `@check_tests`.
    @wrapped_tests_with_validation = true

    @check_tests
  end

  def self.enable_checking_in_tests
    if !@check_tests && @wrapped_tests_with_validation
      raise "Toggle `:tests`-level runtime type checking earlier. " \
        "There are already some methods wrapped with `sig.checked(:tests)`." \
    end

    _toggle_checking_tests(true)
  end

  def self._toggle_checking_tests(checked)
    @check_tests = checked
  end
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
sorbet-runtime-0.4.4289 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4288 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4287 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4286 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4285 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4284 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4283 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4282 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4280 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4279 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4277 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4276 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4275 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4274 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4273 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4272 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4271 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4270 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4269 lib/types/private/runtime_levels.rb
sorbet-runtime-0.4.4263 lib/types/private/runtime_levels.rb