Class: Moneta::Transformer
- Defined in:
- lib/moneta/transformer.rb,
lib/moneta/transformer/config.rb,
lib/moneta/transformer/helper.rb,
lib/moneta/transformer/helper/bson.rb
Overview
Transforms keys and values (Marshal, YAML, JSON, Base64, MD5, …). You can bypass the transformer (e.g. serialization) by using the ‘:raw` option.
Defined Under Namespace
Modules: Helper
Constant Summary collapse
- TRANSFORMER =
Available key/value transformers
{ # Name: [ Type, Load, Dump, Library ], bencode: [ :serialize, '::BEncode.load(%s)', '::BEncode.dump(%s)', 'bencode' ], bert: [ :serialize, '::BERT.decode(%s)', '::BERT.encode(%s)', 'bert' ], bson: [ :serialize, 'Helper::BSON.load(%s)', 'Helper::BSON.dump(%s)', 'bson' ], json: [ :serialize, '::MultiJson.load(%s)', '::MultiJson.dump(%s)', 'multi_json' ], marshal: [ :serialize, '::Marshal.load(%s)', '::Marshal.dump(%s)' ], msgpack: [ :serialize, '::MessagePack.unpack(%s)', '::MessagePack.pack(%s)', 'msgpack' ], ox: [ :serialize, '::Ox.parse_obj(%s)', '::Ox.dump(%s)', 'ox' ], php: [ :serialize, '::PHP.unserialize(%s)', '::PHP.serialize(%s)', 'php_serialize' ], tnet: [ :serialize, '::TNetstring.parse(%s).first', '::TNetstring.dump(%s)', 'tnetstring' ], yaml: [ :serialize, '::YAML.load(%s)', '::YAML.dump(%s)', 'yaml' ], bzip2: [ :compress, 'Helper.bunzip2(%s)', 'Helper.bzip2(%s)', 'rbzip2' ], lz4: [ :compress, '::LZ4.uncompress(%s)', '::LZ4.compress(%s)', 'lz4-ruby' ], lzma: [ :compress, '::LZMA.decompress(%s)', '::LZMA.compress(%s)', 'lzma' ], lzo: [ :compress, '::LZO.decompress(%s)', '::LZO.compress(%s)', 'lzoruby' ], snappy: [ :compress, '::Snappy.inflate(%s)', '::Snappy.deflate(%s)', 'snappy' ], quicklz: [ :compress, '::QuickLZ.decompress(%s)', '::QuickLZ.compress(%s)', 'qlzruby' ], zlib: [ :compress, '::Zlib::Inflate.inflate(%s)', '::Zlib::Deflate.deflate(%s)', 'zlib' ], base64: [ :encode, "%s.unpack('m0').first", "[%s].pack('m0')" ], escape: [ :encode, 'Helper.unescape(%s)', 'Helper.escape(%s)' ], hex: [ :encode, "[%s].pack('H*')", "%s.unpack('H*').first" ], qp: [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ], uuencode: [ :encode, "%s.unpack('u').first", "[%s].pack('u')" ], hmac: [ :hmac, 'Helper.hmacverify(%s, options[:secret] || @secret)', 'Helper.hmacsign(%s, options[:secret] || @secret)', 'openssl' ], truncate: [ :truncate, nil, 'Helper.truncate(%s, @maxlen)', 'digest/md5' ], md5: [ :digest, nil, '::Digest::MD5.hexdigest(%s)', 'digest/md5' ], rmd160: [ :digest, nil, '::Digest::RMD160.hexdigest(%s)', 'digest/rmd160' ], sha1: [ :digest, nil, '::Digest::SHA1.hexdigest(%s)', 'digest/sha1' ], sha256: [ :digest, nil, '::Digest::SHA256.hexdigest(%s)', 'digest/sha2' ], sha384: [ :digest, nil, '::Digest::SHA384.hexdigest(%s)', 'digest/sha2' ], sha512: [ :digest, nil, '::Digest::SHA512.hexdigest(%s)', 'digest/sha2' ], city32: [ :digest, nil, '::CityHash.hash32(%s).to_s(16)', 'cityhash' ], city64: [ :digest, nil, '::CityHash.hash64(%s).to_s(16)', 'cityhash' ], city128: [ :digest, nil, '::CityHash.hash128(%s).to_s(16)', 'cityhash' ], prefix: [ :prefix, nil, '(options[:prefix] || @prefix)+%s' ], spread: [ :spread, nil, 'Helper.spread(%s)' ], to_s: [ :string, nil, '%s.to_s' ], inspect: [ :string, nil, '%s.inspect' ], }
- VALUE_TRANSFORMER =
Allowed value transformers (Read it like a regular expression!)
'serialize? compress? hmac? encode?'
- KEY_TRANSFORMER =
Allowed key transformers (Read it like a regular expression!)
'(serialize | string)? prefix? ((encode? truncate?) | (digest spread?))?'
Instance Attribute Summary
Attributes inherited from Proxy
Class Method Summary collapse
-
.new(adapter, options = {}) ⇒ Transformer
New Moneta transformer.
- .original_new ⇒ Object
Methods inherited from Proxy
#clear, #close, #create, #delete, #features, #increment, #initialize, #key?, #load, #store
Methods included from Defaults
#[], #[]=, #close, #create, #decrement, #features, #fetch, included, #increment, #key?, #supports?
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
This class inherits a constructor from Moneta::Proxy
Class Method Details
.new(adapter, options = {}) ⇒ Transformer
Returns new Moneta transformer.
32 33 34 35 36 37 38 39 40 |
# File 'lib/moneta/transformer.rb', line 32 def new(adapter, = {}) keys = [[:key]].flatten.compact values = [[:value]].flatten.compact raise ArgumentError, 'Option :key or :value is required' if keys.empty? && values.empty? [:prefix] ||= '' if keys.include?(:prefix) name = class_name(keys, values) const_set(name, compile(keys, values)) unless const_defined?(name) const_get(name).original_new(adapter, ) end |
.original_new ⇒ Object
22 |
# File 'lib/moneta/transformer.rb', line 22 alias_method :original_new, :new |