module Traits::DescendantsListing

Public Instance Methods

active_record_descendants(filter = true) click to toggle source
# File lib/traits/descendants_listing.rb, line 24
def active_record_descendants(filter = true)
  load_active_record_descendants!
  ary = ActiveRecord::Base.descendants
  ary.reject! { |ar| filter_active_record_descendant(ar) } if filter
  ary
end
active_record_descendants_loaded?() click to toggle source
# File lib/traits/descendants_listing.rb, line 6
def active_record_descendants_loaded?
  !!@active_record_descendants_loaded
end
filter_active_record_descendant(active_record) click to toggle source
# File lib/traits/descendants_listing.rb, line 31
def filter_active_record_descendant(active_record)
  active_record_filters.any? do |filter|
    case filter
      when Regexp then active_record.name =~ filter
      when String then active_record.name == filter
      when Class  then active_record == filter
      else false
    end
  end
end
invalidate_loaded_active_record_descendants!() click to toggle source
# File lib/traits/descendants_listing.rb, line 20
def invalidate_loaded_active_record_descendants!
  @active_record_descendants_loaded = false
end
load_active_record_descendants!() click to toggle source
# File lib/traits/descendants_listing.rb, line 10
def load_active_record_descendants!
  @active_record_descendants_loaded ||= begin
    # Railties are not necessary here
    # Source: http://stackoverflow.com/questions/6497834/differences-between-railties-and-engines-in-ruby-on-rails-3
    Rails::Engine.subclasses.map(&:instance).each { |i| i.eager_load! }
    Rails.application.eager_load!
    true
  end
end