Sha256: e26f3579abb0fc8680ad60e71adb4e81024cf103611e4f948993cfe88e7023c1

Contents?: true

Size: 522 Bytes

Versions: 3

Compression:

Stored size: 522 Bytes

Contents

# frozen_string_literal: true

module MissionKontrolRelay
  class ModelRetrievalService
    class << self
      def call
        Rails.application.eager_load!
        ActiveRecord::Base.descendants.collect do |table|
          table if valid_table?(table)
        end.compact
      end

      private

      def valid_table?(table)
        table.table_exists? && not_join_table?(table)
      end

      def not_join_table?(table)
        table.to_s.split('::').last.split('_').first != 'HABTM'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mission_kontrol_relay-0.1.2 app/services/mission_kontrol_relay/model_retrieval_service.rb
mission_kontrol_relay-0.1.1 app/services/mission_kontrol_relay/model_retrieval_service.rb
mission_kontrol_relay-0.1.0 app/services/mission_kontrol_relay/model_retrieval_service.rb