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_arels(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, assert_graph_integrity) ⇒ Object
- #init_ic_relations(dependency_attributes) ⇒ 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) ⇒ Object
- #init_storages ⇒ Object
- #init_strategies(strategy, retention_strategy) ⇒ Object
-
#process_retention_strategy(retention_strategy) ⇒ Symbol
Processes passed retention strategy.
-
#process_strategy(strategy_name) ⇒ Symbol
Processes passed strategy, modifies :data_collection_finalized and :saved attributes for db only strategies.
-
#strategy=(strategy) ⇒ Symbol
Saves passed strategy, modifies :data_collection_finalized and :saved attributes for db only strategies.
Instance Method Details
#init_arels(arel) ⇒ Object
172 173 174 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 172 def init_arels(arel) @arel = 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
283 284 285 286 287 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 283 def init_changed_records_stats @created_records = [] @updated_records = [] @deleted_records = [] end |
#init_custom_procs(custom_save_block, custom_reconnect_block) ⇒ Object
261 262 263 264 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 261 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
279 280 281 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 279 def init_data(default_values) @default_values = default_values || {} end |
#init_flags(complete, create_only, check_changed, update_only, use_ar_object, assert_graph_integrity) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 95 def init_flags(complete, create_only, check_changed, update_only, use_ar_object, 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 @assert_graph_integrity = assert_graph_integrity.nil? ? true : assert_graph_integrity end |
#init_ic_relations(dependency_attributes) ⇒ Object
78 79 80 81 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 78 def init_ic_relations(dependency_attributes) @dependency_attributes = dependency_attributes || {} @dependees = Set.new end |
#init_model_attributes(attributes_blacklist, attributes_whitelist, inventory_object_attributes, batch_extra_attributes) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 139 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) @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) ⇒ Object
58 59 60 61 62 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 58 def init_references(manager_ref, manager_ref_allowed_nil, secondary_refs) @manager_ref = manager_ref || %i(ems_ref) @manager_ref_allowed_nil = manager_ref_allowed_nil || [] @secondary_refs = secondary_refs || {} end |
#init_storages ⇒ Object
152 153 154 155 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 152 def init_storages @data_storage = ::InventoryRefresh::InventoryCollection::DataStorage.new(self, @secondary_refs) @references_storage = ::InventoryRefresh::InventoryCollection::ReferencesStorage.new(index_proxy) end |
#init_strategies(strategy, retention_strategy) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 41 def init_strategies(strategy, retention_strategy) @saver_strategy = :concurrent_safe_batch @strategy = process_strategy(strategy) # TODO(lsmola) why don't we just set this strategy based on :archived_at column? Lets do that @retention_strategy = process_retention_strategy(retention_strategy) end |
#process_retention_strategy(retention_strategy) ⇒ Symbol
Processes passed retention strategy
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 326 def process_retention_strategy(retention_strategy) unless retention_strategy if supports_column?(:archived_at) return :archive else return :destroy end end 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_strategy(strategy_name) ⇒ Symbol
Processes passed strategy, modifies :data_collection_finalized and :saved attributes for db only strategies
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 293 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 |
#strategy=(strategy) ⇒ Symbol
Saves passed strategy, modifies :data_collection_finalized and :saved attributes for db only strategies
318 319 320 |
# File 'lib/inventory_refresh/inventory_collection/helpers/initialize_helper.rb', line 318 def strategy=(strategy) @strategy = process_strategy(strategy) end |