Module: Moneta::Transformer::Helper Private
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #escape(value) ⇒ Object private
- #hmacsign(value, secret) ⇒ Object private
- #hmacverify(value, secret) ⇒ Object private
- #spread(value) ⇒ Object private
- #truncate(value, maxlen) ⇒ Object private
- #unescape(value) ⇒ Object private
Instance Method Details
#escape(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 |
# File 'lib/moneta/transformer/helper.rb', line 7 def escape(value) value.gsub(/[^a-zA-Z0-9_-]+/){ '%' + $&.unpack('H2' * $&.bytesize).join('%').upcase } end |
#hmacsign(value, secret) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 |
# File 'lib/moneta/transformer/helper.rb', line 20 def hmacsign(value, secret) OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), secret, value) << value end |
#hmacverify(value, secret) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 18 |
# File 'lib/moneta/transformer/helper.rb', line 15 def hmacverify(value, secret) hash, value = value[0..31], value[32..-1] value if hash == OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), secret, value) end |
#spread(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/moneta/transformer/helper.rb', line 32 def spread(value) ::File.join(value[0..1], value[2..-1]) end |
#truncate(value, maxlen) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 27 28 29 30 |
# File 'lib/moneta/transformer/helper.rb', line 24 def truncate(value, maxlen) if value.size >= maxlen digest = Digest::MD5.hexdigest(value) value = value[0, maxlen-digest.size] << digest end value end |
#unescape(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 |
# File 'lib/moneta/transformer/helper.rb', line 11 def unescape(value) value.gsub(/((?:%[0-9a-fA-F]{2})+)/){ [$1.delete('%')].pack('H*') } end |