diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ccf1a093098..4d92c83ec65 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -960,7 +960,7 @@ def listicon_item(view, id = nil) # Return the icon classname for the list view icon of a db,id pair # this always supersedes listicon_image if not nil def listicon_icon(item) - item.decorate.try(:fonticon) if item.decorator_class? + item.decorate.try(:fonticon) end # Return the image name for the list view icon of a db,id pair @@ -977,7 +977,7 @@ def listicon_image(item, view) when ManageIQ::Providers::CloudManager::AuthKeyPair "100/auth_key_pair.png" else - item.decorate.try(:listicon_image) if item.decorator_class? + item.decorate.try(:listicon_image) end image || default diff --git a/app/decorators/auth_private_key_decorator.rb b/app/decorators/auth_private_key_decorator.rb index eb859c43dba..3608a670ef6 100644 --- a/app/decorators/auth_private_key_decorator.rb +++ b/app/decorators/auth_private_key_decorator.rb @@ -1,6 +1,4 @@ -class AuthPrivateKeyDecorator < Draper::Decorator - delegate_all - +class AuthPrivateKeyDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/configuration_profile_decorator.rb b/app/decorators/configuration_profile_decorator.rb index 565d694d9f2..c2868f7098c 100644 --- a/app/decorators/configuration_profile_decorator.rb +++ b/app/decorators/configuration_profile_decorator.rb @@ -1,6 +1,4 @@ -class ConfigurationProfileDecorator < Draper::Decorator - delegate_all - +class ConfigurationProfileDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/configuration_script_source_decorator.rb b/app/decorators/configuration_script_source_decorator.rb index bb5c91c1f84..1212521b569 100644 --- a/app/decorators/configuration_script_source_decorator.rb +++ b/app/decorators/configuration_script_source_decorator.rb @@ -1,6 +1,4 @@ -class ConfigurationScriptSourceDecorator < Draper::Decorator - delegate_all - +class ConfigurationScriptSourceDecorator < MiqDecorator def fonticon "pficon pficon-repository" end diff --git a/app/decorators/configured_system_decorator.rb b/app/decorators/configured_system_decorator.rb index b40971bd526..3873cc369ca 100644 --- a/app/decorators/configured_system_decorator.rb +++ b/app/decorators/configured_system_decorator.rb @@ -1,6 +1,4 @@ -class ConfiguredSystemDecorator < Draper::Decorator - delegate_all - +class ConfiguredSystemDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/ext_management_system_decorator.rb b/app/decorators/ext_management_system_decorator.rb index b232363da31..27807e1d708 100644 --- a/app/decorators/ext_management_system_decorator.rb +++ b/app/decorators/ext_management_system_decorator.rb @@ -1,6 +1,4 @@ -class ExtManagementSystemDecorator < Draper::Decorator - delegate_all - +class ExtManagementSystemDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/filesystem_decorator.rb b/app/decorators/filesystem_decorator.rb index b85d8ee30c3..793ab23cda4 100644 --- a/app/decorators/filesystem_decorator.rb +++ b/app/decorators/filesystem_decorator.rb @@ -1,6 +1,4 @@ -class FilesystemDecorator < Draper::Decorator - delegate_all - +class FilesystemDecorator < MiqDecorator def fonticon convert = { "dll" => "fa fa-cogs", @@ -15,5 +13,4 @@ def fonticon } convert[name.downcase] || "fa fa-file-o" end - end diff --git a/app/decorators/host_decorator.rb b/app/decorators/host_decorator.rb index c4df41ef57a..9c05ad1504e 100644 --- a/app/decorators/host_decorator.rb +++ b/app/decorators/host_decorator.rb @@ -1,6 +1,4 @@ -class HostDecorator < Draper::Decorator - delegate_all - +class HostDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/manageiq/providers/ansible_tower/automation_manager/configuration_script_decorator.rb b/app/decorators/manageiq/providers/ansible_tower/automation_manager/configuration_script_decorator.rb index c5a8ce154a4..ce590eb15dd 100644 --- a/app/decorators/manageiq/providers/ansible_tower/automation_manager/configuration_script_decorator.rb +++ b/app/decorators/manageiq/providers/ansible_tower/automation_manager/configuration_script_decorator.rb @@ -1,11 +1,11 @@ -class ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScriptDecorator < Draper::Decorator - delegate_all +module ManageIQ::Providers::AnsibleTower + class AutomationManager::ConfigurationScriptDecorator < MiqDecorator + def fonticon + 'product product-template' + end - def fonticon - 'product product-template'.freeze - end - - def listicon_image - '100/configuration_script.png' + def listicon_image + '100/configuration_script.png' + end end end diff --git a/app/decorators/manageiq/providers/ansible_tower/automation_manager/job_decorator.rb b/app/decorators/manageiq/providers/ansible_tower/automation_manager/job_decorator.rb index 0c9cd831132..a0c3a35e44a 100644 --- a/app/decorators/manageiq/providers/ansible_tower/automation_manager/job_decorator.rb +++ b/app/decorators/manageiq/providers/ansible_tower/automation_manager/job_decorator.rb @@ -1,11 +1,11 @@ -class ManageIQ::Providers::AnsibleTower::AutomationManager::JobDecorator < Draper::Decorator - delegate_all +module ManageIQ::Providers::AnsibleTower + class AutomationManager::JobDecorator < MiqDecorator + def fonticon + 'product product-orchestration_stack' + end - def fonticon - 'product product-orchestration_stack'.freeze - end - - def listicon_image - '100/orchestration_stack.png' + def listicon_image + '100/orchestration_stack.png' + end end end diff --git a/app/decorators/manageiq/providers/ansible_tower/automation_manager/playbook_decorator.rb b/app/decorators/manageiq/providers/ansible_tower/automation_manager/playbook_decorator.rb index 66d3a978570..b1c8132b17c 100644 --- a/app/decorators/manageiq/providers/ansible_tower/automation_manager/playbook_decorator.rb +++ b/app/decorators/manageiq/providers/ansible_tower/automation_manager/playbook_decorator.rb @@ -1,11 +1,11 @@ -class ManageIQ::Providers::AnsibleTower::AutomationManager::PlaybookDecorator < Draper::Decorator - delegate_all +module ManageIQ::Providers::AnsibleTower + class AutomationManager::PlaybookDecorator < MiqDecorator + def fonticon + nil + end - def fonticon - nil - end - - def listicon_image - 'svg/vendor-ansible_tower_automation.svg' + def listicon_image + 'svg/vendor-ansible_tower_automation.svg' + end end end diff --git a/app/decorators/manageiq/providers/automation_manager/inventory_group_decorator.rb b/app/decorators/manageiq/providers/automation_manager/inventory_group_decorator.rb index 76c029a291f..0739c06403b 100644 --- a/app/decorators/manageiq/providers/automation_manager/inventory_group_decorator.rb +++ b/app/decorators/manageiq/providers/automation_manager/inventory_group_decorator.rb @@ -1,11 +1,11 @@ -class ManageIQ::Providers::AutomationManager::InventoryGroupDecorator < Draper::Decorator - delegate_all +module ManageIQ::Providers::AutomationManager + class InventoryGroupDecorator < MiqDecorator + def fonticon + 'pficon pficon-folder-close' + end - def fonticon - 'pficon pficon-folder-close'.freeze - end - - def listicon_image - '100/inventory_group.png' + def listicon_image + '100/inventory_group.png' + end end end diff --git a/app/decorators/manageiq/providers/automation_manager/inventory_root_group_decorator.rb b/app/decorators/manageiq/providers/automation_manager/inventory_root_group_decorator.rb index 1d4eb4db203..5d7e92a09a5 100644 --- a/app/decorators/manageiq/providers/automation_manager/inventory_root_group_decorator.rb +++ b/app/decorators/manageiq/providers/automation_manager/inventory_root_group_decorator.rb @@ -1,11 +1,11 @@ -class ManageIQ::Providers::AutomationManager::InventoryRootGroupDecorator < Draper::Decorator - delegate_all +module ManageIQ::Providers::AutomationManager + class InventoryRootGroupDecorator < MiqDecorator + def fonticon + 'pficon pficon-folder-close' + end - def fonticon - 'pficon pficon-folder-close'.freeze - end - - def listicon_image - '100/inventory_group.png' + def listicon_image + '100/inventory_group.png' + end end end diff --git a/app/decorators/manageiq/providers/automation_manager_decorator.rb b/app/decorators/manageiq/providers/automation_manager_decorator.rb index 8f6d3b0d22a..69b51debca1 100644 --- a/app/decorators/manageiq/providers/automation_manager_decorator.rb +++ b/app/decorators/manageiq/providers/automation_manager_decorator.rb @@ -1,7 +1,5 @@ module ManageIQ::Providers - class AutomationManagerDecorator < Draper::Decorator - delegate_all - + class AutomationManagerDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/manageiq/providers/cloud_manager/orchestration_stack_decorator.rb b/app/decorators/manageiq/providers/cloud_manager/orchestration_stack_decorator.rb index ed6c264f402..8ad5b7b50e9 100644 --- a/app/decorators/manageiq/providers/cloud_manager/orchestration_stack_decorator.rb +++ b/app/decorators/manageiq/providers/cloud_manager/orchestration_stack_decorator.rb @@ -1,9 +1,11 @@ -class ManageIQ::Providers::CloudManager::OrchestrationStackDecorator < Draper::Decorator - def fonticon - 'product product-orchestration_stack'.freeze - end +module ManageIQ::Providers + class CloudManager::OrchestrationStackDecorator < MiqDecorator + def fonticon + 'product product-orchestration_stack' + end - def listicon_image - "100/orchestration_stack.png" + def listicon_image + "100/orchestration_stack.png" + end end end diff --git a/app/decorators/manageiq/providers/configuration_manager_decorator.rb b/app/decorators/manageiq/providers/configuration_manager_decorator.rb index 97c371a2841..1d0d9d73c7f 100644 --- a/app/decorators/manageiq/providers/configuration_manager_decorator.rb +++ b/app/decorators/manageiq/providers/configuration_manager_decorator.rb @@ -1,7 +1,5 @@ module ManageIQ::Providers - class ConfigurationManagerDecorator < Draper::Decorator - delegate_all - + class ConfigurationManagerDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/manageiq/providers/hawkular/middleware_manager_decorator.rb b/app/decorators/manageiq/providers/hawkular/middleware_manager_decorator.rb index 8fd10e3f6f4..9b7eedc571a 100644 --- a/app/decorators/manageiq/providers/hawkular/middleware_manager_decorator.rb +++ b/app/decorators/manageiq/providers/hawkular/middleware_manager_decorator.rb @@ -1,5 +1,5 @@ module ManageIQ::Providers::Hawkular - class MiddlewareManagerDecorator < Draper::Decorator + class MiddlewareManagerDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/manageiq/providers/kubernetes/container_manager_decorator.rb b/app/decorators/manageiq/providers/kubernetes/container_manager_decorator.rb index 8d86e3154cf..80ed760f0e0 100644 --- a/app/decorators/manageiq/providers/kubernetes/container_manager_decorator.rb +++ b/app/decorators/manageiq/providers/kubernetes/container_manager_decorator.rb @@ -1,7 +1,7 @@ -class ManageIQ::Providers::Kubernetes::ContainerManagerDecorator < Draper::Decorator - delegate_all - - def listicon_image - "svg/vendor-kubernetes.svg" +module ManageIQ::Providers::Kubernetes + class ContainerManagerDecorator < MiqDecorator + def listicon_image + "svg/vendor-kubernetes.svg" + end end end diff --git a/app/decorators/manageiq/providers/openshift/container_manager_decorator.rb b/app/decorators/manageiq/providers/openshift/container_manager_decorator.rb index 50ce8d790e4..423ad2b3f5e 100644 --- a/app/decorators/manageiq/providers/openshift/container_manager_decorator.rb +++ b/app/decorators/manageiq/providers/openshift/container_manager_decorator.rb @@ -1,7 +1,7 @@ -class ManageIQ::Providers::Openshift::ContainerManagerDecorator < Draper::Decorator - delegate_all - - def listicon_image - "svg/vendor-openshift.svg" +module ManageIQ::Providers::Openshift + class ContainerManagerDecorator < MiqDecorator + def listicon_image + "svg/vendor-openshift.svg" + end end end diff --git a/app/decorators/manageiq/providers/openshift_enterprise/container_manager_decorator.rb b/app/decorators/manageiq/providers/openshift_enterprise/container_manager_decorator.rb index 82ee6b5095e..129d60ddc37 100644 --- a/app/decorators/manageiq/providers/openshift_enterprise/container_manager_decorator.rb +++ b/app/decorators/manageiq/providers/openshift_enterprise/container_manager_decorator.rb @@ -1,7 +1,7 @@ -class ManageIQ::Providers::OpenshiftEnterprise::ContainerManagerDecorator < Draper::Decorator - delegate_all - - def listicon_image - "svg/vendor-openshift_enterprise.svg" +module ManageIQ::Providers::OpenshiftEnterprise + class ContainerManagerDecorator < MiqDecorator + def listicon_image + "svg/vendor-openshift_enterprise.svg" + end end end diff --git a/app/decorators/manageiq/providers/storage_manager/cinder_manager_decorator.rb b/app/decorators/manageiq/providers/storage_manager/cinder_manager_decorator.rb index 42b87db3956..0a77cfb9d48 100644 --- a/app/decorators/manageiq/providers/storage_manager/cinder_manager_decorator.rb +++ b/app/decorators/manageiq/providers/storage_manager/cinder_manager_decorator.rb @@ -1,7 +1,7 @@ -class ManageIQ::Providers::StorageManager::CinderManagerDecorator < Draper::Decorator - delegate_all - - def listicon_image - "svg/vendor-openstack.svg" +module ManageIQ::Providers + class StorageManager::CinderManagerDecorator < MiqDecorator + def listicon_image + "svg/vendor-openstack.svg" + end end end diff --git a/app/decorators/manageiq/providers/storage_manager/swift_manager_decorator.rb b/app/decorators/manageiq/providers/storage_manager/swift_manager_decorator.rb index 121a88cbe8d..c3b8d545c06 100644 --- a/app/decorators/manageiq/providers/storage_manager/swift_manager_decorator.rb +++ b/app/decorators/manageiq/providers/storage_manager/swift_manager_decorator.rb @@ -1,7 +1,7 @@ -class ManageIQ::Providers::StorageManager::SwiftManagerDecorator < Draper::Decorator - delegate_all - - def listicon_image - "svg/vendor-openstack.svg" +module ManageIQ::Providers + class StorageManager::SwiftManagerDecorator < MiqDecorator + def listicon_image + "svg/vendor-openstack.svg" + end end end diff --git a/app/decorators/middleware_datasource_decorator.rb b/app/decorators/middleware_datasource_decorator.rb index abfb62250e1..ef3a469a4c3 100644 --- a/app/decorators/middleware_datasource_decorator.rb +++ b/app/decorators/middleware_datasource_decorator.rb @@ -1,8 +1,6 @@ -class MiddlewareDatasourceDecorator < Draper::Decorator - delegate_all - +class MiddlewareDatasourceDecorator < MiqDecorator def fonticon - 'fa fa-database'.freeze + 'fa fa-database' end def listicon_image diff --git a/app/decorators/middleware_deployment_decorator.rb b/app/decorators/middleware_deployment_decorator.rb index 6b7c1161ebb..7579cc6dfea 100644 --- a/app/decorators/middleware_deployment_decorator.rb +++ b/app/decorators/middleware_deployment_decorator.rb @@ -1,6 +1,4 @@ -class MiddlewareDeploymentDecorator < Draper::Decorator - delegate_all - +class MiddlewareDeploymentDecorator < MiqDecorator def fonticon if name.end_with? '.ear' 'product product-file-ear-o' diff --git a/app/decorators/middleware_domain_decorator.rb b/app/decorators/middleware_domain_decorator.rb index fed766ddc0e..8b3ac984a27 100644 --- a/app/decorators/middleware_domain_decorator.rb +++ b/app/decorators/middleware_domain_decorator.rb @@ -1,8 +1,6 @@ -class MiddlewareDomainDecorator < Draper::Decorator - delegate_all - +class MiddlewareDomainDecorator < MiqDecorator def fonticon - 'pficon-domain'.freeze + 'pficon-domain' end def listicon_image diff --git a/app/decorators/middleware_messaging_decorator.rb b/app/decorators/middleware_messaging_decorator.rb index fbefeececef..1f70615dda7 100644 --- a/app/decorators/middleware_messaging_decorator.rb +++ b/app/decorators/middleware_messaging_decorator.rb @@ -1,8 +1,6 @@ -class MiddlewareMessagingDecorator < Draper::Decorator - delegate_all - +class MiddlewareMessagingDecorator < MiqDecorator def fonticon - 'fa fa-exchange'.freeze + 'fa fa-exchange' end def listicon_image diff --git a/app/decorators/middleware_server_decorator.rb b/app/decorators/middleware_server_decorator.rb index 8698431b88a..7423b1df75d 100644 --- a/app/decorators/middleware_server_decorator.rb +++ b/app/decorators/middleware_server_decorator.rb @@ -1,6 +1,4 @@ -class MiddlewareServerDecorator < Draper::Decorator - delegate_all - +class MiddlewareServerDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/middleware_server_group_decorator.rb b/app/decorators/middleware_server_group_decorator.rb index 1fd5394ae71..ab41e5ceb64 100644 --- a/app/decorators/middleware_server_group_decorator.rb +++ b/app/decorators/middleware_server_group_decorator.rb @@ -1,8 +1,6 @@ -class MiddlewareServerGroupDecorator < Draper::Decorator - delegate_all - +class MiddlewareServerGroupDecorator < MiqDecorator def fonticon - 'pficon-server-group'.freeze + 'pficon-server-group' end def listicon_image diff --git a/app/decorators/miq_action_decorator.rb b/app/decorators/miq_action_decorator.rb index 5220be2ce5d..fbcbbf17859 100644 --- a/app/decorators/miq_action_decorator.rb +++ b/app/decorators/miq_action_decorator.rb @@ -1,6 +1,4 @@ -class MiqActionDecorator < Draper::Decorator - delegate_all - +class MiqActionDecorator < MiqDecorator def fonticon case action_type when 'assign_scan_profile' diff --git a/app/decorators/miq_ae_class_decorator.rb b/app/decorators/miq_ae_class_decorator.rb index 331375fd1e7..35e3e1c5376 100644 --- a/app/decorators/miq_ae_class_decorator.rb +++ b/app/decorators/miq_ae_class_decorator.rb @@ -1,6 +1,4 @@ -class MiqAeClassDecorator < Draper::Decorator - delegate_all - +class MiqAeClassDecorator < MiqDecorator def fonticon 'product product-ae_class' end diff --git a/app/decorators/miq_ae_instance_decorator.rb b/app/decorators/miq_ae_instance_decorator.rb index c2dbea4cf4d..96502110116 100644 --- a/app/decorators/miq_ae_instance_decorator.rb +++ b/app/decorators/miq_ae_instance_decorator.rb @@ -1,6 +1,4 @@ -class MiqAeInstanceDecorator < Draper::Decorator - delegate_all - +class MiqAeInstanceDecorator < MiqDecorator def fonticon 'fa fa-file-text-o' end diff --git a/app/decorators/miq_ae_method_decorator.rb b/app/decorators/miq_ae_method_decorator.rb index bfc299e5c8b..4675e1584f0 100644 --- a/app/decorators/miq_ae_method_decorator.rb +++ b/app/decorators/miq_ae_method_decorator.rb @@ -1,6 +1,4 @@ -class MiqAeMethodDecorator < Draper::Decorator - delegate_all - +class MiqAeMethodDecorator < MiqDecorator def fonticon 'product product-method' end diff --git a/app/decorators/miq_ae_namespace_decorator.rb b/app/decorators/miq_ae_namespace_decorator.rb index 83f1f5d5c89..bf3422d61ea 100644 --- a/app/decorators/miq_ae_namespace_decorator.rb +++ b/app/decorators/miq_ae_namespace_decorator.rb @@ -1,6 +1,4 @@ -class MiqAeNamespaceDecorator < Draper::Decorator - delegate_all - +class MiqAeNamespaceDecorator < MiqDecorator def fonticon 'pficon pficon-folder-close' end diff --git a/app/decorators/miq_event_definition_decorator.rb b/app/decorators/miq_event_definition_decorator.rb index 782e9972c2a..fd729acdac2 100644 --- a/app/decorators/miq_event_definition_decorator.rb +++ b/app/decorators/miq_event_definition_decorator.rb @@ -1,6 +1,4 @@ -class MiqEventDefinitionDecorator < Draper::Decorator - delegate_all - +class MiqEventDefinitionDecorator < MiqDecorator def fonticon convert = { "after_assigned_company_tag" => "fa fa-tag", diff --git a/app/decorators/miq_policy_decorator.rb b/app/decorators/miq_policy_decorator.rb index 1b5b7e4a35a..620680f30d8 100644 --- a/app/decorators/miq_policy_decorator.rb +++ b/app/decorators/miq_policy_decorator.rb @@ -1,6 +1,4 @@ -class MiqPolicyDecorator < Draper::Decorator - delegate_all - +class MiqPolicyDecorator < MiqDecorator def fonticon icon = case towhat when 'Host' diff --git a/app/decorators/miq_request_decorator.rb b/app/decorators/miq_request_decorator.rb index 963f7073b45..1527c810aec 100644 --- a/app/decorators/miq_request_decorator.rb +++ b/app/decorators/miq_request_decorator.rb @@ -1,6 +1,4 @@ -class MiqRequestDecorator < Draper::Decorator - delegate_all - +class MiqRequestDecorator < MiqDecorator def fonticon case request_status.to_s.downcase when "ok" diff --git a/app/decorators/registry_item_decorator.rb b/app/decorators/registry_item_decorator.rb index ef1c4a4deb2..cd954c9e505 100644 --- a/app/decorators/registry_item_decorator.rb +++ b/app/decorators/registry_item_decorator.rb @@ -1,6 +1,4 @@ -class RegistryItemDecorator < Draper::Decorator - delegate_all - +class RegistryItemDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/resource_pool_decorator.rb b/app/decorators/resource_pool_decorator.rb index a6b166e0f6c..d6fa156cc45 100644 --- a/app/decorators/resource_pool_decorator.rb +++ b/app/decorators/resource_pool_decorator.rb @@ -1,6 +1,4 @@ -class ResourcePoolDecorator < Draper::Decorator - delegate_all - +class ResourcePoolDecorator < MiqDecorator def fonticon "pficon pficon-resource-pool" end diff --git a/app/decorators/service_decorator.rb b/app/decorators/service_decorator.rb index 8a2c2e076ec..a2347ffa9b9 100644 --- a/app/decorators/service_decorator.rb +++ b/app/decorators/service_decorator.rb @@ -1,6 +1,4 @@ -class ServiceDecorator < Draper::Decorator - delegate_all - +class ServiceDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/service_resource_decorator.rb b/app/decorators/service_resource_decorator.rb index fd9e00b99f3..8a550d637b9 100644 --- a/app/decorators/service_resource_decorator.rb +++ b/app/decorators/service_resource_decorator.rb @@ -1,6 +1,4 @@ -class ServiceResourceDecorator < Draper::Decorator - delegate_all - +class ServiceResourceDecorator < MiqDecorator def fonticon resource_type.to_s == 'VmOrTemplate' ? 'pficon pficon-virtual-machine' : 'product product-template' end diff --git a/app/decorators/service_template_ansible_tower_decorator.rb b/app/decorators/service_template_ansible_tower_decorator.rb index a4be41ac4bf..80f8054a18d 100644 --- a/app/decorators/service_template_ansible_tower_decorator.rb +++ b/app/decorators/service_template_ansible_tower_decorator.rb @@ -1,6 +1,4 @@ -class ServiceTemplateAnsibleTowerDecorator < Draper::Decorator - delegate_all - +class ServiceTemplateAnsibleTowerDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/service_template_decorator.rb b/app/decorators/service_template_decorator.rb index 2142d0dc77c..856b571be32 100644 --- a/app/decorators/service_template_decorator.rb +++ b/app/decorators/service_template_decorator.rb @@ -1,6 +1,4 @@ -class ServiceTemplateDecorator < Draper::Decorator - delegate_all - +class ServiceTemplateDecorator < MiqDecorator def fonticon nil end diff --git a/app/decorators/vm_or_template_decorator.rb b/app/decorators/vm_or_template_decorator.rb index 98e5d3f4b50..ae2a654657e 100644 --- a/app/decorators/vm_or_template_decorator.rb +++ b/app/decorators/vm_or_template_decorator.rb @@ -1,6 +1,4 @@ -class VmOrTemplateDecorator < Draper::Decorator - delegate_all - +class VmOrTemplateDecorator < MiqDecorator def fonticon nil end diff --git a/app/helpers/quadicon_helper.rb b/app/helpers/quadicon_helper.rb index 3ccfa5c79f1..7a77cb3e476 100644 --- a/app/helpers/quadicon_helper.rb +++ b/app/helpers/quadicon_helper.rb @@ -550,7 +550,7 @@ def render_ems_cluster_quadicon(item, options) def render_non_listicon_single_quadicon(item, options) output = [] - img_path = if item.respond_to?(:decorator_class?) && item.decorator_class? + img_path = if item.decorate item.decorate.try(:listicon_image) else "100/#{item.class.base_class.to_s.underscore}.png" diff --git a/config/initializers/decorate.rb b/config/initializers/decorate.rb new file mode 100644 index 00000000000..ccd25a7900b --- /dev/null +++ b/config/initializers/decorate.rb @@ -0,0 +1,3 @@ +# extending all model instances and classes to have a `decorate` method +ApplicationRecord.send(:extend, MiqDecorator::Klass) +ApplicationRecord.send(:include, MiqDecorator::Instance) diff --git a/lib/miq_decorator.rb b/lib/miq_decorator.rb new file mode 100644 index 00000000000..29408ba101a --- /dev/null +++ b/lib/miq_decorator.rb @@ -0,0 +1,26 @@ +class MiqDecorator < SimpleDelegator + class << self + def for(klass) + decorator = nil + + while decorator.nil? && klass != ApplicationRecord && !klass.nil? + decorator = "#{klass.name}Decorator".safe_constantize + klass = klass.superclass + end + + decorator + end + end +end + +module MiqDecorator::Instance + def decorate + @_decorator ||= MiqDecorator.for(self.class).try(:new, self) + end +end + +module MiqDecorator::Klass + def decorate + @_decorator ||= MiqDecorator.for(self) + end +end diff --git a/spec/helpers/quadicon_helper_spec.rb b/spec/helpers/quadicon_helper_spec.rb index ebaaa7ba6a4..088db6753ab 100644 --- a/spec/helpers/quadicon_helper_spec.rb +++ b/spec/helpers/quadicon_helper_spec.rb @@ -890,7 +890,7 @@ context "when item is not CIM or decorated" do before(:each) do - allow(item).to receive(:decorator_class?) { false } + allow(item).to receive(:decorate).and_return(nil) end it "includes an image with the item's base class name" do diff --git a/spec/lib/miq_decorator_spec.rb b/spec/lib/miq_decorator_spec.rb new file mode 100644 index 00000000000..d506a765c90 --- /dev/null +++ b/spec/lib/miq_decorator_spec.rb @@ -0,0 +1,81 @@ +describe MiqDecorator do + context ".for" do + it "returns nil when a class doesn't have a decorator" do + class TestClassWithout1 + end + + expect(MiqDecorator.for(TestClassWithout1)).to eq(nil) + end + + it "correctly decorates a class when a decorator exists" do + class TestClass2 + end + + class TestClass2Decorator < MiqDecorator + end + + expect(MiqDecorator.for(TestClass2)).to eq(TestClass2Decorator) + end + + it "correctly decorates a namespaced class" do + module TestModule3 + class TestClass3 + end + + class TestClass3Decorator < MiqDecorator + end + end + + expect(MiqDecorator.for(TestModule3::TestClass3)).to eq(TestModule3::TestClass3Decorator) + end + + it "correctly doesn't decorate a namespaced class" do + module TestModule4 + class TestClass4 + end + end + + class TestClass4Decorator < MiqDecorator + end + + expect(MiqDecorator.for(TestModule4::TestClass4)).not_to eq(TestClass4Decorator) + expect(MiqDecorator.for(TestModule4::TestClass4)).to eq(nil) + end + + it "correctly decorates a class when only a decorator for the superclass" do + class TestParent5 + end + + class TestClass5 < TestParent5 + end + + class TestParent5Decorator < MiqDecorator + end + + expect(MiqDecorator.for(TestClass5)).to eq(TestParent5Decorator) + end + + it "correctly decorates an instance" do + class TestClass6 + extend MiqDecorator::Klass + include MiqDecorator::Instance + + attr_reader :x + + def initialize(x) + @x = x + end + end + + class TestClass6Decorator < MiqDecorator + def foo + x + 1 + end + end + + instance = TestClass6.new(123) + + expect(instance.decorate.foo).to eq(124) + end + end +end