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.
- #sweep_scope_from_hash(sweep_scope, available_inventory_collections) ⇒ Object
- #sweep_scope_to_hash(sweep_scope) ⇒ Object
-
#to_hash ⇒ Hash
Serializes InventoryCollection’s data storage into Array of Hashes.
Constructor Details
#initialize(inventory_collection) ⇒ Serialization
Returns a new instance of Serialization.
18 19 20 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 18 def initialize(inventory_collection) @inventory_collection = inventory_collection end |
Instance Attribute Details
#inventory_collection ⇒ Object (readonly)
Returns the value of attribute inventory_collection.
14 15 16 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 14 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
27 28 29 30 31 32 33 34 35 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 27 def from_hash(inventory_objects_data, available_inventory_collections) (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 end |
#sweep_scope_from_hash(sweep_scope, available_inventory_collections) ⇒ Object
37 38 39 40 41 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 37 def sweep_scope_from_hash(sweep_scope, available_inventory_collections) sweep_scope.map do |s| hash_to_data(s, available_inventory_collections).symbolize_keys! end end |
#sweep_scope_to_hash(sweep_scope) ⇒ Object
54 55 56 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 54 def sweep_scope_to_hash(sweep_scope) sweep_scope.map { |x| data_to_hash(x) } end |
#to_hash ⇒ Hash
Serializes InventoryCollection’s data storage into Array of Hashes
46 47 48 49 50 51 52 |
# File 'lib/inventory_refresh/inventory_collection/serialization.rb', line 46 def to_hash { :name => name, :data => data.map { |x| data_to_hash(x.data) }, :partial_data => skeletal_primary_index.index_data.map { |x| data_to_hash(x.data) }, } end |