Sha256: 4f8194547ac699725403b8003ee688fbb22c0f80c191ccdbca2611a0bd7ad129

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require 'tempfile'
require_relative 'gemfile_health_score'

module Polariscope
  module Scanner
    class CodebaseHealthScore
      def initialize(gemfile_content:, gemfile_lock_content:, bundler_audit_config_content:)
        @gemfile_content = gemfile_content
        @gemfile_lock_content = gemfile_lock_content
        @bundler_audit_config_content = bundler_audit_config_content
      end

      def health_score
        return nil if blank?(gemfile_content) || blank?(gemfile_lock_content)

        GemfileHealthScore.new(
          gemfile_path: gemfile_file.path,
          gemfile_lock_content: gemfile_lock_content,
          bundler_audit_config_path: bundler_audit_config_file.path
        ).health_score
      ensure
        gemfile_file.unlink
        bundler_audit_config_file.unlink
      end

      private

      attr_reader :gemfile_content
      attr_reader :gemfile_lock_content
      attr_reader :bundler_audit_config_content

      def gemfile_file
        @gemfile_file ||= begin
          file = Tempfile.new('Gemfile')
          file.write(gemfile_content.gsub("gemspec\n", ''))
          file.close
          file
        end
      end

      def bundler_audit_config_file
        @bundler_audit_config_file ||= begin
          file = Tempfile.new('.bundler-audit.yml')
          file.write(bundler_audit_config_content)
          file.close
          file
        end
      end

      def blank?(value)
        value.nil? || value == ''
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
polariscope-0.1.1 lib/polariscope/scanner/codebase_health_score.rb
polariscope-0.1.0 lib/polariscope/scanner/codebase_health_score.rb