class RgGen::Core::Builder::PluginManager
Constants
- DEFAULT_PLUGSINS
Public Class Methods
new(builder)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 26 def initialize(builder) @builder = builder @plugins = [] end
Public Instance Methods
activate_plugins(**options)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 54 def activate_plugins(**options) options[:no_default_setup] || @plugins.each { |plugin| plugin.default_setup(@builder) } options[:no_optional_setup] || @plugins.each { |plugin| plugin.optional_setup(@builder) } end
load_plugin(setup_path_or_name)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 31 def load_plugin(setup_path_or_name) setup_path_or_name = setup_path_or_name.to_s.strip setup_path, root_dir = if setup_file_directly_given?(setup_path_or_name) [setup_path_or_name, extract_root_dir(setup_path_or_name)] else [get_setup_path(setup_path_or_name), nil] end read_setup_file(setup_path, setup_path_or_name, root_dir) end
load_plugins(plugins, no_default_plugins, activation = true)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 42 def load_plugins(plugins, no_default_plugins, activation = true) RgGen.builder(@builder) merge_plugins(plugins, no_default_plugins).each(&method(:load_plugin)) activation && activate_plugins end
register_plugin(plugin_module, &block)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 48 def register_plugin(plugin_module, &block) plugin?(plugin_module) || (raise Core::PluginError.new('no plugin spec is given')) @plugins << PluginRegistry.new(plugin_module, &block) end
version_info()
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 61 def version_info @plugins.map(&:version_info) end
Private Instance Methods
default_plugins(no_default_plugins)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 113 def default_plugins(no_default_plugins) load_default_plugins?(no_default_plugins) && DEFAULT_PLUGSINS || nil end
extract_root_dir(setup_path)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 72 def extract_root_dir(setup_path) Pathname .new(setup_path) .ascend.find(&method(:rggen_dir?)) &.parent &.to_s end
get_setup_path(name)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 84 def get_setup_path(name) base, sub_directory = name.split('/', 2) base = base.sub(/^rggen[-_]/, '').tr('-', '_') File.join(*['rggen', base, sub_directory, 'setup'].compact) end
load_default_plugins?(no_default_plugins)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 117 def load_default_plugins?(no_default_plugins) return false if no_default_plugins return false if ENV.key?('RGGEN_NO_DEFAULT_PLUGINS') return false if Gem.find_files(DEFAULT_PLUGSINS).empty? true end
merge_plugins(plugins, no_default_plugins)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 103 def merge_plugins(plugins, no_default_plugins) [ *default_plugins(no_default_plugins), *plugins_from_env, *plugins ] end
plugin?(plugin_module)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 129 def plugin?(plugin_module) plugin_module.respond_to?(:plugin_spec) && plugin_module.plugin_spec end
plugins_from_env()
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 124 def plugins_from_env ENV['RGGEN_PLUGINS'] &.split(':')&.map(&:strip)&.reject(&:empty?) end
read_setup_file(setup_path, setup_path_or_name, root_dir)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 90 def read_setup_file(setup_path, setup_path_or_name, root_dir) root_dir && $LOAD_PATH.unshift(root_dir) require setup_path rescue ::LoadError message = if setup_path_or_name == setup_path "cannot load such plugin: #{setup_path_or_name}" else "cannot load such plugin: #{setup_path_or_name} (#{setup_path})" end raise Core::PluginError.new(message) end
rggen_dir?(path)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 80 def rggen_dir?(path) path.each_filename.to_a[-2..-1] == ['lib', 'rggen'] end
setup_file_directly_given?(setup_path_or_name)
click to toggle source
# File lib/rggen/core/builder/plugin_manager.rb, line 67 def setup_file_directly_given?(setup_path_or_name) File.ext(setup_path_or_name) == 'rb' || File.basename(setup_path_or_name, '.*') == 'setup' end