Class: SolrWrapper::ChecksumValidator
- Inherits:
-
Object
- Object
- SolrWrapper::ChecksumValidator
- Defined in:
- lib/solr_wrapper/checksum_validator.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #clean! ⇒ Object
-
#initialize(config) ⇒ ChecksumValidator
constructor
A new instance of ChecksumValidator.
- #validate!(file) ⇒ Object
- #validate?(file) ⇒ Boolean
Constructor Details
#initialize(config) ⇒ ChecksumValidator
Returns a new instance of ChecksumValidator.
5 6 7 |
# File 'lib/solr_wrapper/checksum_validator.rb', line 5 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/solr_wrapper/checksum_validator.rb', line 3 def config @config end |
Instance Method Details
#clean! ⇒ Object
9 10 11 12 |
# File 'lib/solr_wrapper/checksum_validator.rb', line 9 def clean! path = checksum_path(algorithm) FileUtils.remove_entry(path) if File.exist? path end |
#validate!(file) ⇒ Object
19 20 21 22 23 |
# File 'lib/solr_wrapper/checksum_validator.rb', line 19 def validate!(file) unless validate? file raise "Checksum mismatch" unless config.ignore_checksum end end |
#validate?(file) ⇒ Boolean
14 15 16 17 |
# File 'lib/solr_wrapper/checksum_validator.rb', line 14 def validate?(file) return true if config.validate == false Digest.const_get(algorithm.upcase).file(file).hexdigest == expected_sum(algorithm) end |