Module: IdsOfAllDependencies

Includes:
DependencyTree, IdsOfAllDependenciesNested, IdsOfAllDirectDependencies
Included in:
Model
Defined in:
lib/ids_of_all_dependencies.rb

Instance Method Summary collapse

Methods included from DependencyTree

#dependency_tree

Methods included from IdsOfAllDirectDependencies

#ids_of_all_direct_dependencies

Methods included from SymbolsOfAllDirectDependencies

#symbols_of_all_direct_dependencies

Methods included from IdsOfAllDependenciesNested

#ids_of_all_dependencies_nested

Instance Method Details

#ids_of_all_dependencies(to_filter = nil, filtering_strategy = :with_parents) ⇒ Object



205
206
207
# File 'lib/ids_of_all_dependencies.rb', line 205

def ids_of_all_dependencies(to_filter=nil, filtering_strategy=:with_parents)
  ids_of_all_dependencies_with_filtered(to_filter, filtering_strategy)[:main]
end

#ids_of_all_dependencies_with_filtered(to_filter = nil, filtering_strategy = :with_parents) ⇒ Object



209
210
211
212
213
214
215
# File 'lib/ids_of_all_dependencies.rb', line 209

def ids_of_all_dependencies_with_filtered(to_filter=nil, filtering_strategy=:with_parents)
  id_hash = ids_of_all_dependencies_without_reflection(to_filter || {}, filtering_strategy)
  move_wrongly_assigned_to_main(to_filter, id_hash) if to_filter && filtering_strategy == :with_parents
  id_hash[:main].sort_arrays!
  id_hash[:filtered_out].sort_arrays!
  id_hash
end

#ids_of_all_dependencies_without_reflection(to_filter, filtering_strategy = :with_parents) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/ids_of_all_dependencies.rb', line 217

def ids_of_all_dependencies_without_reflection(to_filter, filtering_strategy=:with_parents)
  result = { main: IdHash.new, filtered_out: IdHash.new }
  self_symbol = self.class.name.underscore.to_sym

  self.class.reflect_on_all_associations.map do |association|
    next if association.macro == :belongs_to
    symbol = association.klass.name.underscore.to_sym
    context = { to_filter: to_filter, self_symbol: self_symbol, association: association, strategy: filtering_strategy }

    self.send(association.name).map do |associated_object|
      hash_to_use = get_hash_to_use(result, **context, object: associated_object)
      hash_to_use.add(symbol, associated_object.id)
    end

    result = get_result_with_grandchildren_hashes(result, context)
  end

  result
end