Sha256: 4fe2f63752d99d17e57ffdd89253865715571f8251a189251d291d4b078bfab9

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

module Coverband
  module RailsEagerLoad
    def eager_load!
      Coverband.eager_loading_coverage!
      super
    end
  end
  Rails::Engine.prepend(RailsEagerLoad)

  class Railtie < Rails::Railtie
    initializer "coverband.configure" do |app|
      begin
        app.middleware.use Coverband::BackgroundMiddleware

        if Coverband.configuration.track_views
          COVERBAND_VIEW_TRACKER = if Coverband.coverband_service?
            Coverband::Collectors::ViewTrackerService.new
          else
            Coverband::Collectors::ViewTracker.new
          end

          Coverband.configuration.view_tracker = COVERBAND_VIEW_TRACKER

          ActiveSupport::Notifications.subscribe(/render_partial.action_view|render_template.action_view/) do |name, start, finish, id, payload|
            COVERBAND_VIEW_TRACKER.track_views(name, start, finish, id, payload) unless name.include?("!")
          end
        end
      rescue Redis::CannotConnectError => error
        Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
        Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
      end
    end

    config.after_initialize do
      unless Coverband.tasks_to_ignore?
        Coverband.configure
        Coverband.eager_loading_coverage!
        Coverband.report_coverage
        Coverband.runtime_coverage!
      end
    end

    config.before_configuration do
      unless ENV["COVERBAND_DISABLE_AUTO_START"]
        begin
          Coverband.start
        rescue Redis::CannotConnectError => error
          Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
          Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
        end
      end
    end

    rake_tasks do
      load "coverband/utils/tasks.rb"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
coverband-5.0.0 lib/coverband/utils/railtie.rb
coverband-5.0.0.rc.8 lib/coverband/utils/railtie.rb
coverband-5.0.0.rc.7 lib/coverband/utils/railtie.rb
coverband-5.0.0.rc.6 lib/coverband/utils/railtie.rb
coverband-5.0.0.rc.5 lib/coverband/utils/railtie.rb
coverband-5.0.0.rc.4 lib/coverband/utils/railtie.rb