class TopologicalInventory::Providers::Common::Collector::InventoryCollectionStorage
Attributes
data[RW]
Public Class Methods
new()
click to toggle source
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 10 def initialize @data = {} end
Protected Class Methods
define_collections_reader(collection_key)
click to toggle source
Defines a new attr reader returning InventoryCollection object
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 60 def self.define_collections_reader(collection_key) define_method(collection_key) do add_collection(collection_key, :overwrite => false) end end
Public Instance Methods
[](name)
click to toggle source
Creates collection automatically
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 25 def [](name) add_collection(name, :overwrite => false) end
add_collection(name, overwrite: true)
click to toggle source
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 14 def add_collection(name, overwrite: true) return @data[name] if !@data[name].nil? && !overwrite if ingress_api_model_exists?(name) @data[name] ||= InventoryCollectionWrapper.new(:name => name) else raise NameError, "TopologicalInventoryIngressApiClient::#{name.to_s.classify} doesn't exist" end end
inventory_collections_names()
click to toggle source
@return [Array<Symbol>] array of InventoryCollection object names of the persister
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 30 def inventory_collections_names @data.keys end
method_missing(method_name, *arguments, &block)
click to toggle source
Calls superclass method
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 34 def method_missing(method_name, *arguments, &block) add_collection(method_name, :overwrite => false) # init collection if not exist if inventory_collections_names.include?(method_name) self.class.define_collections_reader(method_name) send(method_name) else super end end
respond_to_missing?(method_name, _include_private = false)
click to toggle source
@return [Boolean] true if InventoryCollection with passed method_name name is defined
Calls superclass method
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 46 def respond_to_missing?(method_name, _include_private = false) ingress_api_model_exists?(method_name) || super end
Protected Instance Methods
ingress_api_model_exists?(method_name)
click to toggle source
# File lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb, line 52 def ingress_api_model_exists?(method_name) class_name = "TopologicalInventoryIngressApiClient::#{method_name.to_s.classify}" # nil test is not enough due to sometimes weird namespace autoloading class_name.safe_constantize.to_s == class_name end