Module: Tapioca::BundlerExt::AutoRequireHook

Extended by:
T::Helpers, T::Sig
Defined in:
lib/tapioca/bundler_ext/auto_require_hook.rb

Overview

This is a module that gets prepended to ‘Bundler::Dependency` and makes sure even gems marked as `require: false` are required during `Bundler.require`.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tapioca/bundler_ext/auto_require_hook.rb', line 26

def enabled?
  @enabled
end

.excluded?(name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/tapioca/bundler_ext/auto_require_hook.rb', line 22

def excluded?(name)
  @exclude.include?(name)
end

.override_require_false(exclude:, &blk) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/tapioca/bundler_ext/auto_require_hook.rb', line 36

def override_require_false(exclude:, &blk)
  @enabled = true
  @exclude = exclude
  blk.call
ensure
  @enabled = false
end

Instance Method Details

#autorequireObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tapioca/bundler_ext/auto_require_hook.rb', line 46

def autorequire
  value = super

  # If autorequire is not enabled, we don't want to force require gems
  return value unless AutoRequireHook.enabled?

  # If the gem is excluded, we don't want to force require it, in case
  # it has side-effects users don't want. For example, `fakefs` gem, if
  # loaded, takes over filesystem operations.
  return value if AutoRequireHook.excluded?(name)

  # If a gem is marked as `require: false`, then its `autorequire`
  # value will be `[]`. But, we want those gems to be loaded for our
  # purposes as well, so we return `nil` in those cases, instead, which
  # means `require: true`.
  return if value == []

  value
end