Module: InventoryRefresh::InventoryCollection::Helpers::QuestionsHelper

Included in:
InventoryRefresh::InventoryCollection
Defined in:
lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb

Instance Method Summary collapse

Instance Method Details

#check_changed?Boolean

Returns true means we want to call .changed? on every ActiveRecord object before saving it.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    true if no more data will be added to this InventoryCollection object, that usually happens after the parsing step is finished



75
76
77
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 75

def data_collection_finalized?
  data_collection_finalized
end

#delete_allowed?Boolean

Returns true means we will delete/soft-delete data.

Returns:

  • (Boolean)

    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

#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.

Returns:

  • (Boolean)

    true if processing of this InventoryCollection object would lead to no operations.



83
84
85
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 83

def noop?
  data.blank? && custom_save_block.nil? && skeletal_primary_index.blank?
end

#saveable?Boolean

Returns true if all dependencies have all data persisted.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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

#supports_column?(column_name) ⇒ Boolean

Returns true if the model_class supports given column.

Parameters:

  • column_name (Symbol, String)

Returns:

  • (Boolean)

    true if the model_class supports given column



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 61

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.include?(column_name.to_s)
  if %w(created_on created_at updated_on updated_at).include?(column_name.to_s)
    include_col &&= ActiveRecord::Base.record_timestamps
  end

  @supported_cols_cache[column_name.to_sym] = include_col
end

#supports_sti?Boolean

Returns true if the model_class supports STI.

Returns:

  • (Boolean)

    true if the model_class supports STI



54
55
56
57
# File 'lib/inventory_refresh/inventory_collection/helpers/questions_helper.rb', line 54

def supports_sti?
  @supports_sti_cache = model_class.column_names.include?("type") if @supports_sti_cache.nil?
  @supports_sti_cache
end

#update_only?Boolean

Returns true means we want to only update data.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    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