Skip to content

Commit

Permalink
Apply PR ManageIQ#15461 patch
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaMuro committed Jul 12, 2017
1 parent 7ce7de2 commit 73b4fd0
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 14 deletions.
41 changes: 27 additions & 14 deletions lib/vmdb/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ def vmdb_plugins
end

def register_vmdb_plugins
Rails.application.railties.each do |railtie|
next unless railtie.class.name.start_with?("ManageIQ::Providers::") || railtie.try(:vmdb_plugin?)
register_vmdb_plugin(railtie)
plugin_registry.plugins.each do |plugin|
register_vmdb_plugin(plugin)
end

@vmdb_plugins
end

def register_vmdb_plugin(engine)
@vmdb_plugins << engine
def register_vmdb_plugin(plugin)
@vmdb_plugins << plugin

register_automate_domains(engine)
register_provider_plugin(engine)
register_automate_domains(plugin)
register_provider_plugin(plugin)

# make sure STI models are recognized
DescendantLoader.instance.descendants_paths << engine.root.join('app')
DescendantLoader.instance.descendants_paths << plugin.root.join('app')
end

def registered_provider_plugin_names
Expand All @@ -47,15 +46,29 @@ def system_automate_domains

private

def register_provider_plugin(engine)
if engine.class.name.start_with?("ManageIQ::Providers::")
provider_name = ManageIQ::Providers::Inflector.provider_name(engine).underscore.to_sym
@registered_provider_plugin_map[provider_name] = engine
def plugin_registry
@plugin_registry ||= build_plugin_registry
end

def build_plugin_registry
if defined?(Rails)
require_relative "plugins/registry/rails.rb"
Vmdb::Plugins::Registry::Rails.instance
else
require_relative "plugins/registry/bundler.rb"
Vmdb::Plugins::Registry::Bundler.instance
end
end

def register_provider_plugin(plugin)
if plugin_registry.provider_plugin? plugin
provider_name = plugin_registry.provider_name(plugin)
@registered_provider_plugin_map[provider_name] = plugin
end
end

def register_automate_domains(engine)
Dir.glob(engine.root.join("content", "automate", "*")).each do |domain_directory|
def register_automate_domains(plugin)
Dir.glob(plugin.root.join("content", "automate", "*")).each do |domain_directory|
@registered_automate_domains << AutomateDomain.new(domain_directory)
end
end
Expand Down
65 changes: 65 additions & 0 deletions lib/vmdb/plugins/registry/bundler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module Vmdb
class Plugins
module Registry
class Bundler
class Plugin
def initialize(spec)
@spec = spec
end

def name
@spec.name
end

def root
@root ||= Pathname.new @spec.gem_dir
end
end

include Singleton

# FIXME: Don't rely on this constant for determining non-provider
# based plugins
#
# Instead find a way to do the equaivalent of `vmdb_plugin?` without
# having to load the class (file in the root, modularize the code
# containing `def vmdb_root?`, etc.)
NON_PROVIDER_PLUGINS = %w(automation_engine content ui-classic).freeze

attr_reader :plugins, :provider_plugins

def initialize
@plugins = fetch_plugins
end

def provider_name(plugin)
plugin.name.gsub("manageiq-providers-", "")
end

def provider_plugin?(plugin)
provider_plugins.include? plugin
end

private

def fetch_plugins
plugin_gems.map do |spec|
Plugin.new(spec)
end
end

def plugin_gems
::Bundler.locked_gems.specs.select do |spec|
spec.name.match(/^manageiq-(providers-.*|#{NON_PROVIDER_PLUGINS.join("|")})$/)
end
end

def provider_plugins
@provider_plugins ||= @plugins.select do |plugin|
plugin.name.start_with?("manageiq-providers-")
end
end
end
end
end
end
37 changes: 37 additions & 0 deletions lib/vmdb/plugins/registry/rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Vmdb
class Plugins
module Registry
class Rails
include Singleton

attr_reader :plugins, :provider_plugins

def initialize
@plugins = fetch_plugins
end

def provider_name(plugin)
ManageIQ::Providers::Inflector.provider_name(plugin).underscore.to_sym
end

def provider_plugin?(plugin)
provider_plugins.include? plugin
end

private

def fetch_plugins
::Rails.application.railties.select do |railtie|
railtie.class.name.start_with?("ManageIQ::Providers::") || railtie.try(:vmdb_plugin?)
end
end

def provider_plugins
@provider_plugins ||= @plugins.select do |engine|
engine.class.name.start_with?("ManageIQ::Providers::")
end
end
end
end
end
end

0 comments on commit 73b4fd0

Please sign in to comment.