Sha256: ac15dc22982f8492491bf31bd924b58f7bd235d3880e0068616373462c69324e

Contents?: true

Size: 686 Bytes

Versions: 3

Compression:

Stored size: 686 Bytes

Contents

# frozen_string_literal: true

require 'bundler/audit/database'

module Polariscope
  module Scanner
    module AuditDatabase
      extend self

      ONE_DAY = 24 * 60 * 60

      def update_if_necessary
        update_audit_database! if database_outdated?
      end

      private

      def update_audit_database!
        Bundler::Audit::Database.update!(quiet: true)
      end

      def database_outdated?
        audit_db_missing? || audit_db_stale?
      end

      def audit_db_missing?
        !Bundler::Audit::Database.exists?
      end

      def audit_db_stale?
        ((Time.now - Bundler::Audit::Database.new.last_updated_at) / ONE_DAY) > 1.0
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polariscope-0.6.0 lib/polariscope/scanner/audit_database.rb
polariscope-0.5.0 lib/polariscope/scanner/audit_database.rb
polariscope-0.4.0 lib/polariscope/scanner/audit_database.rb