paulnsorensen/lifesaver

View on GitHub
lib/lifesaver/notification/dependent_associations.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Lifesaver
  module Notification
    class DependentAssociations
      def initialize(klass)
        @class = klass
      end

      def fetch
        @dependent_associations ||= populate
      end

      private

      def populate
        dependent_associations = []
        @class.reflect_on_all_associations.each do |association|
          if association.options[:dependent].present?
            dependent_associations << association.name.to_sym
          end
        end
        dependent_associations
      end
    end
  end
end