Module: InventoryRefresh::InventoryCollection::Helpers::QuestionsHelper
- Included in:
- InventoryRefresh::InventoryCollection
- Defined in:
- lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb
Instance Method Summary collapse
-
#check_changed? ⇒ Boolean
True means we want to call .changed? on every ActiveRecord object before saving it.
-
#complete? ⇒ Boolean
True means the data is not complete, leading to only creating and updating data.
-
#create_allowed? ⇒ Boolean
True means we will delete/soft-delete data.
-
#create_only? ⇒ Boolean
True means that only create of new data is allowed.
-
#data_collection_finalized? ⇒ Boolean
True if no more data will be added to this InventoryCollection object, that usually happens after the parsing step is finished.
-
#delete_allowed? ⇒ Boolean
True means we will delete/soft-delete data.
-
#delete_complement_noop? ⇒ Boolean
True if processing InventoryCollection will not lead to deleting the complement of passed ids.
-
#noop? ⇒ Boolean
True if processing of this InventoryCollection object would lead to no operations.
-
#parallel_safe? ⇒ Boolean
True if we are using a saver strategy that allows saving in parallel processes.
-
#saveable? ⇒ Boolean
True if all dependencies have all data persisted.
-
#saved? ⇒ Boolean
True if the whole InventoryCollection object has all data persisted.
-
#saving_noop? ⇒ Boolean
True if processing InventoryCollection will not lead to any created/updated/deleted record.
-
#supports_column?(column_name) ⇒ Boolean
True if the model_class supports given column.
-
#supports_sti? ⇒ Boolean
True if the model_class supports STI.
-
#targeted? ⇒ Boolean
True is processing of this InventoryCollection will be in targeted mode.
-
#update_only? ⇒ Boolean
True means we want to only update data.
-
#use_ar_object? ⇒ Boolean
True means we want to use ActiveRecord object for writing attributes and we want to perform casting on all columns.
Instance Method Details
#check_changed? ⇒ Boolean
Returns true means we want to call .changed? on every ActiveRecord object before saving it.
8 9 10 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 8 def check_changed? check_changed end |
#complete? ⇒ Boolean
Returns true means the data is not complete, leading to only creating and updating data.
19 20 21 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 19 def complete? complete end |
#create_allowed? ⇒ Boolean
Returns true means we will delete/soft-delete data.
34 35 36 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 34 def create_allowed? !update_only? end |
#create_only? ⇒ Boolean
Returns true means that only create of new data is allowed.
39 40 41 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 39 def create_only? create_only end |
#data_collection_finalized? ⇒ Boolean
Returns true if no more data will be added to this InventoryCollection object, that usually happens after the parsing step is finished.
81 82 83 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 81 def data_collection_finalized? data_collection_finalized end |
#delete_allowed? ⇒ Boolean
Returns true means we will delete/soft-delete data.
29 30 31 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 29 def delete_allowed? complete? && !update_only? end |
#delete_complement_noop? ⇒ Boolean
Returns true if processing InventoryCollection will not lead to deleting the complement of passed ids.
105 106 107 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 105 def delete_complement_noop? all_manager_uuids.nil? end |
#noop? ⇒ Boolean
True if processing of this InventoryCollection object would lead to no operations. Then we use this marker to stop processing of the InventoryCollector object very soon, to avoid a lot of unnecessary Db queries, etc.
94 95 96 97 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 94 def noop? # If this InventoryCollection doesn't do anything. it can easily happen for targeted/batched strategies. saving_noop? && delete_complement_noop? end |
#parallel_safe? ⇒ Boolean
Returns true if we are using a saver strategy that allows saving in parallel processes.
54 55 56 57 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 54 def parallel_safe? return @parallel_safe unless @parallel_safe.nil? @parallel_safe = %i[concurrent_safe concurrent_safe_batch].include?(saver_strategy) end |
#saveable? ⇒ Boolean
Returns true if all dependencies have all data persisted.
49 50 51 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 49 def saveable? dependencies.all?(&:saved?) end |
#saved? ⇒ Boolean
Returns true if the whole InventoryCollection object has all data persisted.
44 45 46 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 44 def saved? saved end |
#saving_noop? ⇒ Boolean
Returns true if processing InventoryCollection will not lead to any created/updated/deleted record.
100 101 102 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 100 def saving_noop? saving_targeted_parent_collection_noop? || saving_targeted_child_collection_noop? || saving_full_collection_noop? end |
#supports_column?(column_name) ⇒ Boolean
Returns true if the model_class supports given column.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 67 def supports_column?(column_name) @supported_cols_cache ||= {} return @supported_cols_cache[column_name.to_sym] unless @supported_cols_cache[column_name.to_sym].nil? include_col = model_class&.column_names.to_a.include?(column_name.to_s) if %w[created_on created_at updated_on updated_at].include?(column_name.to_s) include_col &&= ActiveRecord::Base. end @supported_cols_cache[column_name.to_sym] = include_col end |
#supports_sti? ⇒ Boolean
Returns true if the model_class supports STI.
60 61 62 63 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 60 def supports_sti? return @supports_sti unless @supports_sti.nil? @supports_sti = model_class&.column_names.to_a.include?("type") end |
#targeted? ⇒ Boolean
Returns true is processing of this InventoryCollection will be in targeted mode.
86 87 88 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 86 def targeted? targeted end |
#update_only? ⇒ Boolean
Returns true means we want to only update data.
24 25 26 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 24 def update_only? update_only end |
#use_ar_object? ⇒ Boolean
Returns true means we want to use ActiveRecord object for writing attributes and we want to perform casting on all columns.
14 15 16 |
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 14 def use_ar_object? use_ar_object end |