Class: Grably::Digest::ProductDigest
- Inherits:
-
Object
- Object
- Grably::Digest::ProductDigest
- Defined in:
- lib/grably/core/digest.rb
Overview
Describes product state. If two digests for same file differs assume file changed
Instance Attribute Summary collapse
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(product, mtime:, size:, md5:) ⇒ ProductDigest
constructor
A new instance of ProductDigest.
Constructor Details
#initialize(product, mtime:, size:, md5:) ⇒ ProductDigest
Returns a new instance of ProductDigest.
13 14 15 16 17 18 |
# File 'lib/grably/core/digest.rb', line 13 def initialize(product, mtime:, size:, md5:) @product = product @mtime = mtime @size = size @md5 = md5 end |
Instance Attribute Details
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
11 12 13 |
# File 'lib/grably/core/digest.rb', line 11 def md5 @md5 end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
11 12 13 |
# File 'lib/grably/core/digest.rb', line 11 def mtime @mtime end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
11 12 13 |
# File 'lib/grably/core/digest.rb', line 11 def product @product end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
11 12 13 |
# File 'lib/grably/core/digest.rb', line 11 def size @size end |
Class Method Details
.[](*products) ⇒ Object
37 38 39 |
# File 'lib/grably/core/digest.rb', line 37 def self.[](*products) products.map { |p| of_product(p) } end |
.of_product(product) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/grably/core/digest.rb', line 41 def self.of_product(product) product = Product.new(product) if product.is_a?(String) raise 'Expected string or Product got ' + product.inspect unless product.is_a? Product src = product.src raise 'File does not exist' unless File.exist? src ProductDigest.new( product, mtime: File.mtime(src), size: File.size(src), md5: ::Digest::MD5.hexdigest(IO.binread(src)) ) end |
Instance Method Details
#==(other) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/grably/core/digest.rb', line 24 def ==(other) [ product == other.product, mtime == other.mtime, size == other.size, md5 == other.md5 ].all? end |
#eql?(other) ⇒ Boolean
20 21 22 |
# File 'lib/grably/core/digest.rb', line 20 def eql?(other) self == other end |
#hash ⇒ Object
33 34 35 |
# File 'lib/grably/core/digest.rb', line 33 def hash md5.to_i end |