Class: InventoryRefresh::InventoryCollection::Serialization
- Inherits:
-
Object
- Object
- InventoryRefresh::InventoryCollection::Serialization
- Defined in:
- lib/inventory_refresh/inventory_collection/serialization.rb
Instance Attribute Summary collapse
-
#inventory_collection ⇒ Object
readonly
Returns the value of attribute inventory_collection.
Instance Method Summary collapse
-
#from_hash(inventory_objects_data, available_inventory_collections) ⇒ Object
Loads InventoryCollection data from it’s serialized form into existing InventoryCollection object.
-
#initialize(inventory_collection) ⇒ Serialization
constructor
A new instance of Serialization.
-
#to_hash ⇒ Hash
Serializes InventoryCollection’s data storage into Array of Hashes.
Constructor Details
#initialize(inventory_collection) ⇒ Serialization
20 21 22 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 20 def initialize(inventory_collection) @inventory_collection = inventory_collection end |
Instance Attribute Details
#inventory_collection ⇒ Object (readonly)
Returns the value of attribute inventory_collection.
16 17 18 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 16 def inventory_collection @inventory_collection end |
Instance Method Details
#from_hash(inventory_objects_data, available_inventory_collections) ⇒ Object
Loads InventoryCollection data from it’s serialized form into existing InventoryCollection object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 29 def from_hash(inventory_objects_data, available_inventory_collections) targeted_scope.merge!(inventory_objects_data["manager_uuids"].map(&:symbolize_keys!)) inventory_objects_data['data'].each do |inventory_object_data| build(hash_to_data(inventory_object_data, available_inventory_collections).symbolize_keys!) end inventory_objects_data['partial_data'].each do |inventory_object_data| skeletal_primary_index.build(hash_to_data(inventory_object_data, available_inventory_collections).symbolize_keys!) end # TODO(lsmola) add support for all_manager_uuids serialization # self.all_manager_uuids = inventory_objects_data['all_manager_uuids'] end |
#to_hash ⇒ Hash
Serializes InventoryCollection’s data storage into Array of Hashes
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 47 def to_hash { :name => name, # TODO(lsmola) we do not support nested references here, should we? :manager_uuids => targeted_scope.primary_references.values.map(&:full_reference), :all_manager_uuids => all_manager_uuids, :data => data.map { |x| data_to_hash(x.data) }, :partial_data => skeletal_primary_index.index_data.map { |x| data_to_hash(x.data) }, } end |