Sha256: 6e59967cd7ab5e1d94ced6014553f5010f757e687b9d631ac07fd0c35320fa2a

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module DataIntegrity
    # CLI application class
    class CLI
      def initialize; end

      def run
        require_rails

        results = cops.map do |cop_class|
          ActiveRecord::Base.descendants.each do |model|
            cop_class.new(model).call
          end
        end

        ActiveRecord::DataIntegrity::Collector.render

        exit(1) if results.include?(false)
      end

      private

      def cops
        @cops ||= ActiveRecord::DataIntegrity::Cop.descendants
      end

      def require_rails
        # Rails load ugly hack :)
        require File.expand_path('config/environment', Dir.pwd)
        Kernel.const_set(:APP_PATH, File.expand_path('config/application', Dir.pwd))
        Rails.application.eager_load!
        Rails.logger.level = 0
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-data_integrity-0.1.0 lib/active_record/data_integrity/cli.rb