Module: InventoryRefresh::InventoryCollection::Helpers::InitializeHelper
- Included in:
- InventoryRefresh::InventoryCollection
- Defined in:
- lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb
Instance Method Summary collapse
- #init_all_manager_uuids(all_manager_uuids, all_manager_uuids_scope, all_manager_uuids_timestamp) ⇒ Object
- #init_arels(arel, targeted_arel) ⇒ Object
- #init_basic_properties(association, model_class, name, parent) ⇒ Object
- #init_changed_records_stats ⇒ Object
- #init_custom_procs(custom_save_block, custom_reconnect_block) ⇒ Object
- #init_data(default_values) ⇒ Object
- #init_flags(complete, create_only, check_changed, update_only, use_ar_object, targeted, assert_graph_integrity) ⇒ Object
- #init_ic_relations(dependency_attributes, parent_inventory_collections = nil) ⇒ Object
- #init_model_attributes(attributes_blacklist, attributes_whitelist, inventory_object_attributes, batch_extra_attributes) ⇒ Object
- #init_references(manager_ref, manager_ref_allowed_nil, secondary_refs, manager_uuids) ⇒ Object
- #init_storages ⇒ Object
- #init_strategies(strategy, saver_strategy, retention_strategy, delete_method) ⇒ Object
-
#process_retention_strategy(retention_strategy) ⇒ Symbol
Processes passed retention strategy.
-
#process_saver_strategy(saver_strategy) ⇒ Symbol
Processes passed saver strategy.
-
#process_strategy(strategy_name) ⇒ Symbol
Processes passed strategy, modifies :data_collection_finalized and :saved attributes for db only strategies.
Instance Method Details
#init_all_manager_uuids(all_manager_uuids, all_manager_uuids_scope, all_manager_uuids_timestamp) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 101 def init_all_manager_uuids(all_manager_uuids, all_manager_uuids_scope, ) # TODO(lsmola) Should we refactor this to use references too? @all_manager_uuids = all_manager_uuids @all_manager_uuids_scope = all_manager_uuids_scope @all_manager_uuids_timestamp = end |
#init_arels(arel, targeted_arel) ⇒ Object
277 278 279 280 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 277 def init_arels(arel, targeted_arel) @arel = arel @targeted_arel = targeted_arel end |
#init_basic_properties(association, model_class, name, parent) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 16 def init_basic_properties(association, model_class, name, parent) @association = association @model_class = model_class @name = name || association || model_class.to_s.demodulize.tableize @parent = parent || nil end |
#init_changed_records_stats ⇒ Object
389 390 391 392 393 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 389 def init_changed_records_stats @created_records = [] @updated_records = [] @deleted_records = [] end |
#init_custom_procs(custom_save_block, custom_reconnect_block) ⇒ Object
367 368 369 370 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 367 def init_custom_procs(custom_save_block, custom_reconnect_block) @custom_save_block = custom_save_block @custom_reconnect_block = custom_reconnect_block end |
#init_data(default_values) ⇒ Object
385 386 387 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 385 def init_data(default_values) @default_values = default_values || {} end |
#init_flags(complete, create_only, check_changed, update_only, use_ar_object, targeted, assert_graph_integrity) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 180 def init_flags(complete, create_only, check_changed, update_only, use_ar_object, targeted, assert_graph_integrity) @complete = complete.nil? ? true : complete @create_only = create_only.nil? ? false : create_only @check_changed = check_changed.nil? ? true : check_changed @saved = false @update_only = update_only.nil? ? false : update_only @use_ar_object = use_ar_object || false @targeted = !!targeted @assert_graph_integrity = assert_graph_integrity.nil? ? true : assert_graph_integrity end |
#init_ic_relations(dependency_attributes, parent_inventory_collections = nil) ⇒ Object
160 161 162 163 164 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 160 def init_ic_relations(dependency_attributes, parent_inventory_collections = nil) @dependency_attributes = dependency_attributes || {} @dependees = Set.new @parent_inventory_collections = parent_inventory_collections end |
#init_model_attributes(attributes_blacklist, attributes_whitelist, inventory_object_attributes, batch_extra_attributes) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 227 def init_model_attributes(attributes_blacklist, attributes_whitelist, inventory_object_attributes, batch_extra_attributes) @attributes_blacklist = Set.new @attributes_whitelist = Set.new @batch_extra_attributes = batch_extra_attributes || [] @inventory_object_attributes = inventory_object_attributes @internal_attributes = %i[__feedback_edge_set_parent __parent_inventory_collections __all_manager_uuids_scope] @transitive_dependency_attributes = Set.new blacklist_attributes!(attributes_blacklist) if attributes_blacklist.present? whitelist_attributes!(attributes_whitelist) if attributes_whitelist.present? end |
#init_references(manager_ref, manager_ref_allowed_nil, secondary_refs, manager_uuids) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 74 def init_references(manager_ref, manager_ref_allowed_nil, secondary_refs, manager_uuids) @manager_ref = manager_ref || %i[ems_ref] @manager_ref_allowed_nil = manager_ref_allowed_nil || [] @secondary_refs = secondary_refs || {} @manager_uuids = manager_uuids || [] end |
#init_storages ⇒ Object
240 241 242 243 244 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 240 def init_storages @data_storage = ::InventoryRefresh::InventoryCollection::DataStorage.new(self, @secondary_refs) @references_storage = ::InventoryRefresh::InventoryCollection::ReferencesStorage.new(index_proxy) @targeted_scope = ::InventoryRefresh::InventoryCollection::ReferencesStorage.new(index_proxy).merge!(@manager_uuids) end |
#init_strategies(strategy, saver_strategy, retention_strategy, delete_method) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 53 def init_strategies(strategy, saver_strategy, retention_strategy, delete_method) @saver_strategy = process_saver_strategy(saver_strategy) @strategy = process_strategy(strategy) @retention_strategy = process_retention_strategy(retention_strategy) @delete_method = delete_method || :destroy end |
#process_retention_strategy(retention_strategy) ⇒ Symbol
Processes passed retention strategy
441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 441 def process_retention_strategy(retention_strategy) return unless retention_strategy retention_strategy = retention_strategy.to_sym case retention_strategy when :destroy, :archive retention_strategy else raise "Unknown InventoryCollection retention strategy: :#{retention_strategy}, allowed strategies are "\ ":destroy and :archive" end end |
#process_saver_strategy(saver_strategy) ⇒ Symbol
Processes passed saver strategy
399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 399 def process_saver_strategy(saver_strategy) return :default unless saver_strategy saver_strategy = saver_strategy.to_sym case saver_strategy when :default, :batch, :concurrent_safe_batch saver_strategy else raise "Unknown InventoryCollection saver strategy: :#{saver_strategy}, allowed strategies are "\ ":default, :batch and :concurrent_safe_batch" end end |
#process_strategy(strategy_name) ⇒ Symbol
Processes passed strategy, modifies :data_collection_finalized and :saved attributes for db only strategies
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 416 def process_strategy(strategy_name) self.data_collection_finalized = false return unless strategy_name strategy_name = strategy_name.to_sym case strategy_name when :local_db_cache_all self.data_collection_finalized = true self.saved = true when :local_db_find_references self.saved = true when :local_db_find_missing_references nil else raise "Unknown InventoryCollection strategy: :#{strategy_name}, allowed strategies are :local_db_cache_all, "\ ":local_db_find_references and :local_db_find_missing_references." end strategy_name end |