Skip to content

Commit

Permalink
Merge pull request #17736 from slemrmartin/ic-builder-cleanup
Browse files Browse the repository at this point in the history
Removing add_inventory_collection and has_inventory interfaces
  • Loading branch information
agrare authored Jul 24, 2018
2 parents 9824734 + 6ca376d commit d549a31
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 1,588 deletions.
76 changes: 0 additions & 76 deletions app/models/manager_refresh/inventory/automation_manager.rb

This file was deleted.

16 changes: 0 additions & 16 deletions app/models/manager_refresh/inventory/cloud_manager.rb

This file was deleted.

75 changes: 0 additions & 75 deletions app/models/manager_refresh/inventory/core.rb

This file was deleted.

64 changes: 0 additions & 64 deletions app/models/manager_refresh/inventory/middleware_manager.rb

This file was deleted.

77 changes: 0 additions & 77 deletions app/models/manager_refresh/inventory/persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,6 @@ def to_json
JSON.dump(to_hash)
end

# Creates method on class that lazy initializes an InventoryCollection
#
# @param options [Hash] kwargs for ManagerRefresh::InventoryCollection instantiation
def self.has_inventory(options)
name = (options[:association] || options[:model_class].name.pluralize.underscore).to_sym

supported_collections << name

define_method(name) do
collections[name] ||= begin
collection_options = options.dup

collection_options[:parent] = manager unless collection_options.key?(:parent)
collection_options[:parent] = @target if collection_options[:parent] == :target

if collection_options[:builder_params]
collection_options[:builder_params] = collection_options[:builder_params].transform_values do |value|
if value.respond_to?(:call)
value.call(self)
else
value
end
end
end
::ManagerRefresh::InventoryCollection.new(collection_options)
end
end
end

# @return [Config::Options] Options for the manager type
def options
@options ||= Settings.ems_refresh[manager.class.ems_type]
Expand Down Expand Up @@ -119,54 +90,6 @@ def initialize_inventory_collections
# can be implemented in a subclass
end

# Adds 1 ManagerRefresh::InventoryCollection under a target.collections using :association key as index
#
# @param options [Hash] Hash used for ManagerRefresh::InventoryCollection initialize
def add_inventory_collection(options)
options[:parent] = manager if !options.key?(:parent) && manager

if options[:builder_params]
options[:builder_params] = options[:builder_params].transform_values do |value|
if value.respond_to?(:call)
value.call(self)
else
value
end
end
end

collections[options[:association]] = ::ManagerRefresh::InventoryCollection.new(options)
end

# Adds multiple inventory collections with the same data
#
# @param default [ManagerRefresh::InventoryCollectionDefault] Default
# @param inventory_collections [Array] Array of method names for passed default parameter
# @param options [Hash] Hash used for ManagerRefresh::InventoryCollection initialize
def add_inventory_collections(default, inventory_collections, options = {})
inventory_collections.each do |inventory_collection|
add_inventory_collection(shared_options.merge(default.send(inventory_collection, options)))
end
end

# Adds remaining inventory collections with the same data
#
# @param defaults [Array] Array of ManagerRefresh::InventoryCollectionDefault
# @param options [Hash] Hash used for ManagerRefresh::InventoryCollection initialize
def add_remaining_inventory_collections(defaults, options = {})
defaults.each do |default|
# Get names of all inventory collections defined in passed classes with Defaults
all_inventory_collections = default.methods - ::ManagerRefresh::InventoryCollectionDefault.methods
# Get names of all defined inventory_collections
defined_inventory_collections = inventory_collections_names

# Add all missing inventory_collections with defined init_data
add_inventory_collections(default,
all_inventory_collections - defined_inventory_collections,
options)
end
end

# @return [Hash] entire Persister object serialized to hash
def to_hash
collections_data = collections.map do |_, collection|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module ManagerRefresh
class InventoryCollection
class Builder
# TODO: (mslemr) Remove /manager_refresh/inventory/[core, automation_manager, cloud_manager, ?middleware_manager?].rb
# TODO: (mslemr) think about lib/generators/provider/templates/app/models/manageiq/providers/%provider_name%/inventory/persister/cloud_manager.rb
class AutomationManager < ::ManagerRefresh::InventoryCollection::Builder
def configuration_scripts
default_manager_ref
Expand Down
Loading

0 comments on commit d549a31

Please sign in to comment.