Class: Bundler::Plugin::Index
- Inherits:
-
Object
- Object
- Bundler::Plugin::Index
- Defined in:
- lib/bundler/plugin/index.rb
Defined Under Namespace
Classes: CommandConflict, SourceConflict
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
Instance Method Summary collapse
-
#command_plugin(command) ⇒ Object
Fetch the name of plugin handling the command.
-
#global_index_file ⇒ Object
Path where the global index file is stored.
-
#hook_plugins(event) ⇒ Object
Returns the list of plugin names handling the passed event.
-
#index_file ⇒ Object
Path of default index file.
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #installed?(name) ⇒ Boolean
-
#installed_in_plugin_root?(name) ⇒ Boolean
This plugin is installed inside the .bundle/plugin directory, and thus is managed solely by Bundler.
- #installed_plugins ⇒ Object
- #load_paths(name) ⇒ Object
-
#local_index_file ⇒ Object
Path where the local index file is stored.
- #plugin_commands(plugin) ⇒ Object
- #plugin_path(name) ⇒ Object
-
#register_plugin(name, path, load_paths, commands, sources, hooks) ⇒ Object
This function is to be called when a new plugin is installed.
- #source?(source) ⇒ Boolean
- #source_plugin(name) ⇒ Object
- #unregister_plugin(name) ⇒ Object
Constructor Details
#initialize ⇒ Index
Returns a new instance of Index.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bundler/plugin/index.rb', line 25 def initialize @plugin_paths = {} @commands = {} @sources = {} @hooks = {} @load_paths = {} begin load_index(global_index_file, true) rescue GenericSystemCallError # no need to fail when on a read-only FS, for example nil rescue ArgumentError => e # ruby 3.4 checks writability in Dir.tmpdir raise unless e.&.include?("could not find a temporary directory") nil end load_index(local_index_file) if SharedHelpers.in_bundle? end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
23 24 25 |
# File 'lib/bundler/plugin/index.rb', line 23 def commands @commands end |
Instance Method Details
#command_plugin(command) ⇒ Object
Fetch the name of plugin handling the command
114 115 116 |
# File 'lib/bundler/plugin/index.rb', line 114 def command_plugin(command) @commands[command] end |
#global_index_file ⇒ Object
Path where the global index file is stored
96 97 98 |
# File 'lib/bundler/plugin/index.rb', line 96 def global_index_file Plugin.global_root.join("index") end |
#hook_plugins(event) ⇒ Object
Returns the list of plugin names handling the passed event
139 140 141 |
# File 'lib/bundler/plugin/index.rb', line 139 def hook_plugins(event) @hooks[event] || [] end |
#index_file ⇒ Object
Path of default index file
91 92 93 |
# File 'lib/bundler/plugin/index.rb', line 91 def index_file Plugin.root.join("index") end |
#installed?(name) ⇒ Boolean
118 119 120 |
# File 'lib/bundler/plugin/index.rb', line 118 def installed?(name) @plugin_paths[name] end |
#installed_in_plugin_root?(name) ⇒ Boolean
This plugin is installed inside the .bundle/plugin directory, and thus is managed solely by Bundler
145 146 147 148 149 |
# File 'lib/bundler/plugin/index.rb', line 145 def installed_in_plugin_root?(name) return false unless (path = installed?(name)) path.start_with?("#{Plugin.root}/") end |
#installed_plugins ⇒ Object
122 123 124 |
# File 'lib/bundler/plugin/index.rb', line 122 def installed_plugins @plugin_paths.keys end |
#load_paths(name) ⇒ Object
109 110 111 |
# File 'lib/bundler/plugin/index.rb', line 109 def load_paths(name) @load_paths[name] end |
#local_index_file ⇒ Object
Path where the local index file is stored
101 102 103 |
# File 'lib/bundler/plugin/index.rb', line 101 def local_index_file Plugin.local_root.join("index") end |
#plugin_commands(plugin) ⇒ Object
126 127 128 |
# File 'lib/bundler/plugin/index.rb', line 126 def plugin_commands(plugin) @commands.find_all {|_, n| n == plugin }.map(&:first) end |
#plugin_path(name) ⇒ Object
105 106 107 |
# File 'lib/bundler/plugin/index.rb', line 105 def plugin_path(name) Pathname.new @plugin_paths[name] end |
#register_plugin(name, path, load_paths, commands, sources, hooks) ⇒ Object
This function is to be called when a new plugin is installed. This function shall add the functions of the plugin to existing maps and also the name to source location.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bundler/plugin/index.rb', line 54 def register_plugin(name, path, load_paths, commands, sources, hooks) old_commands = @commands.dup common = commands & @commands.keys raise CommandConflict.new(name, common) unless common.empty? commands.each {|c| @commands[c] = name } common = sources & @sources.keys raise SourceConflict.new(name, common) unless common.empty? sources.each {|k| @sources[k] = name } hooks.each do |event| event_hooks = (@hooks[event] ||= []) << name event_hooks.uniq! end @plugin_paths[name] = path @load_paths[name] = load_paths save_index rescue StandardError @commands = old_commands raise end |
#source?(source) ⇒ Boolean
130 131 132 |
# File 'lib/bundler/plugin/index.rb', line 130 def source?(source) @sources.key? source end |
#source_plugin(name) ⇒ Object
134 135 136 |
# File 'lib/bundler/plugin/index.rb', line 134 def source_plugin(name) @sources[name] end |
#unregister_plugin(name) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bundler/plugin/index.rb', line 78 def unregister_plugin(name) @commands.delete_if {|_, v| v == name } @sources.delete_if {|_, v| v == name } @hooks.each do |hook, names| names.delete(name) @hooks.delete(hook) if names.empty? end @plugin_paths.delete(name) @load_paths.delete(name) save_index end |