| 1 |
# frozen_string_literal: true |
| 2 |
|
| 3 |
module Bundler |
| 4 |
module Plugin |
| 5 |
module Events |
| 6 |
def self.define(const, event) |
| 7 |
const = const.to_sym.freeze |
| 8 |
if const_defined?(const) && const_get(const) != event |
| 9 |
raise ArgumentError, "Attempting to reassign #{const} to a different value" |
| 10 |
end |
| 11 |
const_set(const, event) unless const_defined?(const) |
| 12 |
@events ||= {} |
| 13 |
@events[event] = const |
| 14 |
end |
| 15 |
private_class_method :define |
| 16 |
|
| 17 |
def self.reset |
| 18 |
@events.each_value do |const| |
| 19 |
remove_const(const) |
| 20 |
end |
| 21 |
@events = nil |
| 22 |
end |
| 23 |
private_class_method :reset |
| 24 |
|
| 25 |
# Check if an event has been defined |
| 26 |
# @param event [String] An event to check |
| 27 |
# @return [Boolean] A boolean indicating if the event has been defined |
| 28 |
def self.defined_event?(event) |
| 29 |
@events ||= {} |
| 30 |
@events.key?(event) |
| 31 |
end |
| 32 |
|
| 33 |
# @!parse |
| 34 |
# A hook called before each individual gem is installed |
| 35 |
# Includes a Bundler::ParallelInstaller::SpecInstallation. |
| 36 |
# No state, error, post_install_message will be present as nothing has installed yet |
| 37 |
# GEM_BEFORE_INSTALL = "before-install" |
| 38 |
define :GEM_BEFORE_INSTALL, "before-install" |
| 39 |
|
| 40 |
# @!parse |
| 41 |
# A hook called after each individual gem is installed |
| 42 |
# Includes a Bundler::ParallelInstaller::SpecInstallation. |
| 43 |
# - If state is failed, an error will be present. |
| 44 |
# - If state is success, a post_install_message may be present. |
| 45 |
# GEM_AFTER_INSTALL = "after-install" |
| 46 |
define :GEM_AFTER_INSTALL, "after-install" |
| 47 |
|
| 48 |
# @!parse |
| 49 |
# A hook called before any gems install |
| 50 |
# Includes an Array of Bundler::Dependency objects |
| 51 |
# GEM_BEFORE_INSTALL_ALL = "before-install-all" |
| 52 |
define :GEM_BEFORE_INSTALL_ALL, "before-install-all" |
| 53 |
|
| 54 |
# @!parse |
| 55 |
# A hook called after any gems install |
| 56 |
# Includes an Array of Bundler::Dependency objects |
| 57 |
# GEM_AFTER_INSTALL_ALL = "after-install-all" |
| 58 |
define :GEM_AFTER_INSTALL_ALL, "after-install-all" |
| 59 |
end |
| 60 |
end |
| 61 |
end |