forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce7de2
commit 73b4fd0
Showing
3 changed files
with
129 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |