класс Bundler::Plugin::Index
Атрибуты
Общественные методы класса
# 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
end
load_index(local_index_file) if SharedHelpers.in_bundle?
end Общественные методы экземпляра
# File lib/bundler/plugin/index.rb, line 95 def command_plugin(command) @commands[command] end
Получить имя плагина, обрабатывающего команду
# File lib/bundler/plugin/index.rb, line 77
def global_index_file
Plugin.global_root.join("index")
end Путь к файлу глобального индекса
# File lib/bundler/plugin/index.rb, line 112 def hook_plugins(event) @hooks[event] || [] end
Возвращает список имён плагинов, обрабатывающих переданное событие
# File lib/bundler/plugin/index.rb, line 72
def index_file
Plugin.root.join("index")
end Путь к файлу индекса по умолчанию
# File lib/bundler/plugin/index.rb, line 99 def installed?(name) @plugin_paths[name] end
# File lib/bundler/plugin/index.rb, line 90 def load_paths(name) @load_paths[name] end
# File lib/bundler/plugin/index.rb, line 82
def local_index_file
Plugin.local_root.join("index")
end Путь к файлу локального индекса
# File lib/bundler/plugin/index.rb, line 86 def plugin_path(name) Pathname.new @plugin_paths[name] end
# File lib/bundler/plugin/index.rb, line 50
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 {|e| (@hooks[e] ||= []) << name }
@plugin_paths[name] = path
@load_paths[name] = load_paths
save_index
rescue StandardError
@commands = old_commands
raise
end Вызывается при установке нового плагина. Добавляет функции плагина в существующие карты, а также имя к расположению источника.
@param [String] имя плагина для регистрации @param [String] путь к установленному плагину @param [Array<String>] load_paths для плагина @param [Array<String>] команды, обрабатываемые плагином @param [Array<String>] источники, обрабатываемые плагином
# File lib/bundler/plugin/index.rb, line 103 def source?(source) @sources.key? source end
# File lib/bundler/plugin/index.rb, line 107 def source_plugin(name) @sources[name] end
Приватные методы экземпляра
# File lib/bundler/plugin/index.rb, line 124
def load_index(index_file, global = false)
SharedHelpers.filesystem_access(index_file, :read) do |index_f|
valid_file = index_f && index_f.exist? && !index_f.size.zero?
break unless valid_file
data = index_f.read
require "bundler/yaml_serializer"
index = YAMLSerializer.load(data)
@commands.merge!(index["commands"])
@hooks.merge!(index["hooks"])
@load_paths.merge!(index["load_paths"])
@plugin_paths.merge!(index["plugin_paths"])
@sources.merge!(index["sources"]) unless global
end
end Читает файл индекса из каталога и инициализирует переменные экземпляра.
Пропускает источники, если второй параметр true @param [Pathname] путь к файлу индекса @param [Boolean] является ли файл индекса глобальным индексом
# File lib/bundler/plugin/index.rb, line 145
def save_index
index = {
"commands" => @commands,
"hooks" => @hooks,
"load_paths" => @load_paths,
"plugin_paths" => @plugin_paths,
"sources" => @sources,
}
require "bundler/yaml_serializer"
SharedHelpers.filesystem_access(index_file) do |index_f|
FileUtils.mkdir_p(index_f.dirname)
File.open(index_f, "w") {|f| f.puts YAMLSerializer.dump(index) }
end
end Должен вызываться при изменении любых переменных экземпляра. Сохраняет переменные экземпляра в формате YAML. (Переменные экземпляра должны быть только парами ключ-значение String)
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.