Sha256: cb04cdda450ce2629f469da7eb2b3d0fda528a664016a231261dad30cf138906

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

require "uri"
require "net/http"
require "net/https"

module GemVersionCheck
  class Project

    def initialize(project, options = {})
      @project = project
      @only = options[:only] || []
      @except = options[:except] || []
    end

    def name
      @project
    end

    def report
      @report ||= generate_report
    end

    def generate_report
      @check_failed = false
      result = []
      with_progress_bar(spec_names) do |spec_name|
        dependency = Dependency.new(spec_name, nil, allow_prerelease_dependencies: allow_prerelease_dependencies?, ignore_major_version_change: ignore_major_version_change?)
        dependency.check(lock_file)
        result << dependency

        @check_failed = true if dependency.used? && !dependency.valid?
      end
      result
    end

    def check_failed?
      @check_failed
    end

    def lock_file
      @lock_file ||= begin
        content = LockfileFetcher.new(@project).content
        Lockfile.new(content)
      end
    end

    private

    def with_progress_bar(elements)
      pb = ProgressBar.new("Fetch specs", lock_file.total) if display_status?
      elements.each do |el|
        yield el
        pb.inc if display_status?
      end
      pb.clear if display_status?
    end

    def allow_prerelease_dependencies?
      GemVersionCheck.configuration.allow_prerelease_dependencies
    end

    def display_status?
      GemVersionCheck.configuration.show_progress_bar
    end

    def ignore_major_version_change?
      GemVersionCheck.configuration.ignore_major_version_change
    end

    def spec_names
      if @only.any?
        @only
      elsif @except.any?
        all_spec_names - @except
      else
        all_spec_names
      end
    end

    def all_spec_names
      lock_file.spec_names
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gem_version_check-0.4.0 lib/gem_version_check/project.rb
gem_version_check-0.3.1 lib/gem_version_check/project.rb