Sha256: c935ad30a32d81c9cc3da7f2ca0850c69e38a9f725a5c6d530e40b96e369042a

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

module RubyAudit
  class Database < Bundler::Audit::Database
    def advisories_for(name, type)
      return enum_for(__method__, name, type) unless block_given?

      each_advisory_path_for(name, type) do |path|
        yield Bundler::Audit::Advisory.load(path)
      end
    end

    def check_ruby(ruby, &block)
      check(ruby, 'rubies', &block)
    end

    def check_library(library, &block)
      check(library, 'libraries', &block)
    end

    def check(object, type = 'gems')
      return enum_for(__method__, object, type) unless block_given?

      advisories_for(object.name, type) do |advisory|
        yield advisory if advisory.vulnerable?(object.version)
      end
    end

    def stale
      if File.directory?(USER_PATH) &&
         File.exist?(File.join(USER_PATH, '.git'))
        ts = Time.parse(
          `cd #{USER_PATH} && git log --date=iso8601 --pretty="%cd" -1`).utc
        ts < (Date.today - 7).to_time
      else
        true
      end
    end

    protected

    def each_advisory_path(&block)
      Dir.glob(File.join(@path, '{gems,libraries,rubies}', '*', '*.yml'),
               &block)
    end

    def each_advisory_path_for(name, type = 'gems', &block)
      Dir.glob(File.join(@path, type, name, '*.yml'), &block)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_audit-1.0.0 lib/ruby_audit/database.rb