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.
move EMS.supports :create_security_group to SecurityGroup.supports :c…
…reate The SecurityGroups (the specific EMS implementation) hold this domain knowledge so the question is delegated from the ems (technically a NetworkManager) to the appropriate SecurityGroup in question. Introducing a mechanism to make it easier to delegate these questions to child models.
- Loading branch information
Showing
3 changed files
with
82 additions
and
106 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,43 @@ | ||
module ExtManagementSystem::SupportsAttribute | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
# define an attribute that is used by the ui to detect that a feature is supported | ||
# These are often defined with an actual supports feature, | ||
# but it is often not necessary and we are trying avoid | ||
# | ||
# This is mostly used instead of supports but is very related to the supports end goal | ||
# | ||
# examples: | ||
# | ||
# a) supports_attribute :supports_create_security_group, child_model: SecurityGroup, feature: create | ||
# | ||
# def supports_create_security_group | ||
# ext_management_system.class::ChildModel.supports?(feature) | ||
# end | ||
# | ||
# NOTE: we could derive this name, but it is too hard to search | ||
# | ||
# b) supports_attribute feature: :add_volume_mapping | ||
# | ||
# def supports_add_volume_mapping | ||
# supports?(:add_volume_mapping) | ||
# end | ||
# | ||
def supports_attribute(colname = nil, feature: :create, child_model: nil) | ||
feature = feature.to_sym | ||
|
||
if child_model | ||
define_method(colname) do | ||
class_by_ems(child_model)&.supports?(feature) || false | ||
end | ||
else | ||
define_method(colname || "supports_#{feature}") do | ||
supports?(feature) | ||
end | ||
end | ||
|
||
virtual_attribute colname, :boolean | ||
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