Class: Shrine::Plugins::Signature::SignatureCalculator
- Inherits:
-
Object
- Object
- Shrine::Plugins::Signature::SignatureCalculator
- Defined in:
- lib/shrine/plugins/signature.rb
Constant Summary collapse
- SUPPORTED_ALGORITHMS =
[:sha1, :sha256, :sha384, :sha512, :md5, :crc32]
- SUPPORTED_FORMATS =
[:none, :hex, :base64]
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #call(io) ⇒ Object
-
#initialize(algorithm, format:) ⇒ SignatureCalculator
constructor
A new instance of SignatureCalculator.
Constructor Details
#initialize(algorithm, format:) ⇒ SignatureCalculator
Returns a new instance of SignatureCalculator.
58 59 60 61 62 63 64 |
# File 'lib/shrine/plugins/signature.rb', line 58 def initialize(algorithm, format:) raise Error, "unknown hash algorithm #{algorithm.inspect}, supported algorithms are: #{SUPPORTED_ALGORITHMS.join(",")}" unless SUPPORTED_ALGORITHMS.include?(algorithm) raise Error, "unknown hash format #{format.inspect}, supported formats are: #{SUPPORTED_FORMATS.join(",")}" unless SUPPORTED_FORMATS.include?(format) @algorithm = algorithm @format = format end |
Instance Attribute Details
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
56 57 58 |
# File 'lib/shrine/plugins/signature.rb', line 56 def algorithm @algorithm end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
56 57 58 |
# File 'lib/shrine/plugins/signature.rb', line 56 def format @format end |
Instance Method Details
#call(io) ⇒ Object
66 67 68 69 |
# File 'lib/shrine/plugins/signature.rb', line 66 def call(io) hash = send(:"calculate_#{algorithm}", io) send(:"encode_#{format}", hash) end |