Sha256: b6c427191d06be4914d5097ff4cfe517ea2e08af3f3a2a8399418c154965557d

Contents?: true

Size: 872 Bytes

Versions: 9

Compression:

Stored size: 872 Bytes

Contents

module SolrWrapper
  class MD5
    attr_reader :config
    def initialize(config)
      @config = config
    end

    def clean!
      FileUtils.remove_entry(config.md5sum_path) if File.exist? config.md5sum_path
    end

    def validate?(file)
      return true if config.validate == false

      Digest::MD5.file(file).hexdigest == expected_sum
    end

    def validate!(file)
      unless validate? file
        raise "MD5 mismatch" unless config.ignore_md5sum
      end
    end

    private

      def expected_sum
        @md5sum ||= config.md5sum
        @md5sum ||= read_file
      end

      def read_file
        open(md5file).read.split(" ").first
      end

      def md5file
        unless File.exist? config.md5sum_path
          Downloader.fetch_with_progressbar config.md5url, config.md5sum_path
        end

        config.md5sum_path
      end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
solr_wrapper-1.2.0 lib/solr_wrapper/md5.rb
solr_wrapper-1.1.0 lib/solr_wrapper/md5.rb
solr_wrapper-1.0.0 lib/solr_wrapper/md5.rb
solr_wrapper-0.23.0 lib/solr_wrapper/md5.rb
solr_wrapper-0.22.0 lib/solr_wrapper/md5.rb
solr_wrapper-0.21.0 lib/solr_wrapper/md5.rb
solr_wrapper-0.20.0 lib/solr_wrapper/md5.rb
solr_wrapper-0.19.0 lib/solr_wrapper/md5.rb
solr_wrapper-0.18.1 lib/solr_wrapper/md5.rb