Module: Scenic::Cascade::DependentFinder::ClassMethods

Defined in:
lib/scenic/cascade/dependent_finder.rb

Overview

Provides class methods to injected class

Instance Method Summary collapse

Instance Method Details

#view_dependents_of(view_name, recursive: false) ⇒ Object Also known as: view_dependants_of



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scenic/cascade/dependent_finder.rb', line 36

def view_dependents_of(view_name, recursive: false)
  query = ActiveRecord::Base.sanitize_sql_array([DEPENDANT_SQL, view_name])
  raw_dependencies = ActiveRecord::Base.connection.select_all(query).to_a
  dependencies = raw_dependencies.map { |dep| Scenic::Cascade::Dependency.from_hash(dep) }

  return [] if dependencies.empty?
  return dependencies unless recursive

  dependencies.flat_map do |dependency|
    [dependency, *view_dependents_of(dependency.from.name)]
  end
end