Class: Gemvault::BundlerPluginIndex
- Inherits:
-
Object
- Object
- Gemvault::BundlerPluginIndex
- 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
- #file ⇒ Object
-
#initialize(root) ⇒ BundlerPluginIndex
constructor
A new instance of BundlerPluginIndex.
-
#registered?(plugin) ⇒ Boolean
Whether plugin_paths currently lists
plugin. -
#restore(snapshot) ⇒ Object
Puts the index back the way
snapshotrecorded it; restoringnilremoves an index that did not exist at snapshot time. -
#snapshot ⇒ Object
:call-seq: snapshot -> String or nil.
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
#file ⇒ Object
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.
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 |
#snapshot ⇒ Object
: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 |