Class: Gemvault::BundlerPluginRoot

Inherits:
Object
  • Object
show all
Defined in:
lib/gemvault/bundler_plugin_root.rb

Overview

Where Bundler keeps plugin data for a directory.

Bundler::Plugin.root answers the project-local .bundle/plugin when SharedHelpers.in_bundle? holds, and the global ~/.bundle/plugin when it does not. Since in_bundle? is just "was a Gemfile found", a project can own a plugin root that Bundler declines to look in.

Constant Summary collapse

LOCAL_DIR =
".bundle/plugin".freeze

Instance Method Summary collapse

Constructor Details

#initialize(dir: Dir.pwd, gemfile: BundlerGemfile.new(dir: dir), env: ENV) ⇒ BundlerPluginRoot

Returns a new instance of BundlerPluginRoot.



16
17
18
19
20
# File 'lib/gemvault/bundler_plugin_root.rb', line 16

def initialize(dir: Dir.pwd, gemfile: BundlerGemfile.new(dir: dir), env: ENV)
  @dir = Pathname(dir)
  @gemfile = gemfile
  @env = env
end

Instance Method Details

#consultedObject

The plugin root Bundler will consult here: beside the Gemfile when one was found, the project's own root when doctor points Bundler at it (see #unreachable?), the global root otherwise.



41
42
43
44
45
46
# File 'lib/gemvault/bundler_plugin_root.rb', line 41

def consulted
  return @gemfile.path.dirname / LOCAL_DIR if @gemfile.exist?
  return local if unreachable?

  global
end

#globalObject

Where Bundler keeps plugins for a user outside any project, mirroring Bundler's user_bundle_path lookup for plugins: BUNDLE_USER_PLUGIN names the root directly, BUNDLE_USER_HOME relocates .bundle, and the home directory is the default.



31
32
33
34
35
36
# File 'lib/gemvault/bundler_plugin_root.rb', line 31

def global
  named = @env["BUNDLE_USER_PLUGIN"]
  return Pathname(named) if named

  Pathname(@env["BUNDLE_USER_HOME"] || File.join(Dir.home, ".bundle")) / "plugin"
end

#localObject

The project's own plugin root, whether or not Bundler would consult it.



23
24
25
# File 'lib/gemvault/bundler_plugin_root.rb', line 23

def local
  @dir.expand_path / LOCAL_DIR
end

#unreachable?Boolean

Whether this project has a plugin root that Bundler currently ignores.

bundler/inline installs plugins into /.bundle/plugin, having set BUNDLE_GEMFILE to a bare "Gemfile" for the duration of the script. A later command in that same directory sets no such variable and finds no Gemfile on disk, so Bundler falls back to the global root and reports the plugin as not installed -- while the entry sits here.

Returns:

  • (Boolean)


55
56
57
# File 'lib/gemvault/bundler_plugin_root.rb', line 55

def unreachable?
  !@gemfile.exist? && local.directory?
end