Class: TopologicalInventory::Providers::Common::Collector::InventoryCollectionStorage
- Inherits:
-
Object
- Object
- TopologicalInventory::Providers::Common::Collector::InventoryCollectionStorage
- Defined in:
- lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Creates collection automatically.
- #add_collection(name, overwrite: true) ⇒ Object
-
#initialize ⇒ InventoryCollectionStorage
constructor
A new instance of InventoryCollectionStorage.
-
#inventory_collections_names ⇒ Array<Symbol>
Array of InventoryCollection object names of the persister.
- #method_missing(method_name, *arguments, &block) ⇒ Object
-
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
True if InventoryCollection with passed method_name name is defined.
Constructor Details
#initialize ⇒ InventoryCollectionStorage
Returns a new instance of InventoryCollectionStorage.
10 11 12 |
# File 'lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb', line 10 def initialize @data = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# 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 |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb', line 6 def data @data end |
Instance Method Details
#[](name) ⇒ Object
Creates collection automatically
25 26 27 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# 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 ⇒ Array<Symbol>
Returns array of InventoryCollection object names of the persister.
30 31 32 |
# File 'lib/topological_inventory/providers/common/collector/inventory_collection_storage.rb', line 30 def inventory_collections_names @data.keys end |
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
Returns true if InventoryCollection with passed method_name name is defined.
46 47 48 |
# 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 |