Class: Gemvault::BundlerPluginIndex

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

Overview

Bundler's plugin index file inside a plugin root.

The uninstall step of gemvault doctor clears entries from this file, and the reinstall that follows can fail for reasons unrelated to the plugin. Snapshot and restore make that pair transactional: a repair that cannot finish puts the index back instead of leaving the machine with no plugin registered at all (issue #27).

The plugin_paths section is scanned textually rather than parsed as YAML: loading a YAML library into doctor's process invites the same stdlib-activation conflicts as issue #25, and bundler's own emitter writes one two-space-indented "name: path" line per plugin.

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ BundlerPluginIndex

Returns a new instance of BundlerPluginIndex.



18
19
20
# File 'lib/gemvault/bundler_plugin_index.rb', line 18

def initialize(root)
  @root = Pathname(root)
end

Instance Method Details

#fileObject



22
23
24
# File 'lib/gemvault/bundler_plugin_index.rb', line 22

def file
  @root / "index"
end

#registered?(plugin) ⇒ Boolean

Whether plugin_paths currently lists plugin.

Returns:

  • (Boolean)


27
28
29
# File 'lib/gemvault/bundler_plugin_index.rb', line 27

def registered?(plugin)
  plugin_paths.any? { |line| line.match?(/\A\s{2}#{Regexp.escape(plugin)}:/) }
end

#restore(snapshot) ⇒ Object

Puts the index back the way snapshot recorded it; restoring nil removes an index that did not exist at snapshot time.



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

def restore(snapshot)
  return file.write(snapshot) if snapshot

  file.delete if file.exist?
end

#snapshotObject

:call-seq:

snapshot -> String or nil

The index content as it stands, nil when no index exists.



35
36
37
# File 'lib/gemvault/bundler_plugin_index.rb', line 35

def snapshot
  file.file? ? file.read : nil
end