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.
Defined Under Namespace
Modules: BSON
Instance Method Summary collapse
- #bunzip2(value) ⇒ Object private
- #bzip2(value) ⇒ Object private
- #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
#bunzip2(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.
44 45 46 |
# File 'lib/moneta/transformer/helper.rb', line 44 def bunzip2(value) ::RBzip2::Decompressor.new(::StringIO.new(value)).read end |
#bzip2(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.
36 37 38 39 40 41 42 |
# File 'lib/moneta/transformer/helper.rb', line 36 def bzip2(value) io = ::StringIO.new bz = ::RBzip2::Compressor.new(io) bz.write(value) bz.close io.string end |
#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.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.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 |