moneta 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rspec +4 -0
- data/.travis.yml +83 -32
- data/.yardopts +6 -1
- data/CHANGES +30 -0
- data/CONTRIBUTORS +4 -0
- data/Gemfile +28 -36
- data/LICENSE +1 -1
- data/README.md +136 -67
- data/SPEC.md +70 -0
- data/feature_matrix.yaml +235 -0
- data/lib/active_support/cache/moneta_store.rb +102 -6
- data/lib/moneta.rb +9 -2
- data/lib/moneta/adapters/activerecord.rb +258 -98
- data/lib/moneta/adapters/activesupportcache.rb +133 -0
- data/lib/moneta/adapters/cassandra.rb +290 -44
- data/lib/moneta/adapters/client.rb +11 -2
- data/lib/moneta/adapters/couch.rb +179 -25
- data/lib/moneta/adapters/datamapper.rb +1 -0
- data/lib/moneta/adapters/daybreak.rb +21 -4
- data/lib/moneta/adapters/dbm.rb +7 -7
- data/lib/moneta/adapters/file.rb +11 -1
- data/lib/moneta/adapters/gdbm.rb +7 -7
- data/lib/moneta/adapters/kyotocabinet.rb +66 -1
- data/lib/moneta/adapters/leveldb.rb +27 -1
- data/lib/moneta/adapters/lmdb.rb +29 -1
- data/lib/moneta/adapters/lruhash.rb +30 -0
- data/lib/moneta/adapters/memcached/dalli.rb +50 -5
- data/lib/moneta/adapters/memcached/native.rb +11 -4
- data/lib/moneta/adapters/memory.rb +2 -0
- data/lib/moneta/adapters/mongo/base.rb +32 -7
- data/lib/moneta/adapters/mongo/moped.rb +59 -2
- data/lib/moneta/adapters/mongo/official.rb +40 -0
- data/lib/moneta/adapters/pstore.rb +56 -8
- data/lib/moneta/adapters/redis.rb +79 -19
- data/lib/moneta/adapters/sdbm.rb +7 -7
- data/lib/moneta/adapters/sequel.rb +440 -39
- data/lib/moneta/adapters/sqlite.rb +74 -10
- data/lib/moneta/adapters/tdb.rb +16 -1
- data/lib/moneta/adapters/tokyocabinet.rb +7 -1
- data/lib/moneta/adapters/tokyotyrant.rb +22 -0
- data/lib/moneta/cache.rb +11 -1
- data/lib/moneta/expires.rb +110 -8
- data/lib/moneta/lock.rb +21 -2
- data/lib/moneta/mixins.rb +279 -3
- data/lib/moneta/pool.rb +15 -6
- data/lib/moneta/proxy.rb +46 -2
- data/lib/moneta/server.rb +5 -1
- data/lib/moneta/shared.rb +27 -11
- data/lib/moneta/stack.rb +1 -1
- data/lib/moneta/synchronize.rb +2 -8
- data/lib/moneta/transformer.rb +152 -2
- data/lib/moneta/transformer/config.rb +2 -0
- data/lib/moneta/transformer/helper.rb +2 -2
- data/lib/moneta/version.rb +1 -1
- data/lib/moneta/weak_each_key.rb +74 -0
- data/lib/moneta/wrapper.rb +25 -0
- data/moneta.gemspec +2 -2
- data/script/benchmarks +174 -62
- data/script/parallel-tests +58 -83
- data/script/start-hbase +46 -0
- data/script/start-services +9 -2
- data/script/update-feature-matrix +148 -0
- data/spec/active_support/cache_moneta_store_spec.rb +132 -109
- data/spec/features/concurrent_create.rb +21 -0
- data/spec/features/concurrent_increment.rb +32 -0
- data/spec/features/create.rb +25 -0
- data/spec/features/create_expires.rb +19 -0
- data/spec/features/default_expires.rb +15 -0
- data/spec/features/each_key.rb +119 -0
- data/spec/features/expires.rb +291 -0
- data/spec/features/features.rb +16 -0
- data/spec/features/increment.rb +98 -0
- data/spec/features/marshallable_key.rb +43 -0
- data/spec/features/marshallable_value.rb +7 -0
- data/spec/features/multiprocess.rb +8 -0
- data/spec/features/not_create.rb +7 -0
- data/spec/features/not_each_key.rb +7 -0
- data/spec/features/not_increment.rb +13 -0
- data/spec/features/not_persist.rb +9 -0
- data/spec/features/null.rb +66 -0
- data/spec/features/persist.rb +14 -0
- data/spec/features/returndifferent.rb +9 -0
- data/spec/features/returnsame.rb +9 -0
- data/spec/features/store.rb +261 -0
- data/spec/features/store_large.rb +13 -0
- data/spec/features/transform_value.rb +44 -0
- data/spec/features/transform_value_expires.rb +41 -0
- data/spec/helper.rb +391 -74
- data/spec/moneta/adapters/activerecord/adapter_activerecord_existing_connection_spec.rb +59 -0
- data/spec/moneta/adapters/activerecord/adapter_activerecord_spec.rb +118 -0
- data/spec/moneta/adapters/activerecord/standard_activerecord_spec.rb +18 -0
- data/spec/moneta/adapters/activerecord/standard_activerecord_with_expires_spec.rb +24 -0
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_spec.rb +51 -0
- data/spec/moneta/adapters/activesupportcache/adapter_activesupportcache_with_default_expires_spec.rb +51 -0
- data/spec/moneta/adapters/cassandra/adapter_cassandra_spec.rb +17 -0
- data/spec/moneta/adapters/cassandra/adapter_cassandra_with_default_expires_spec.rb +18 -0
- data/spec/moneta/adapters/cassandra/helper.rb +18 -0
- data/spec/moneta/adapters/cassandra/standard_cassandra_spec.rb +18 -0
- data/spec/moneta/adapters/client/adapter_client_spec.rb +11 -0
- data/spec/moneta/adapters/client/standard_client_tcp_spec.rb +23 -0
- data/spec/moneta/adapters/client/standard_client_unix_spec.rb +12 -0
- data/spec/moneta/adapters/cookie/adapter_cookie_spec.rb +7 -0
- data/spec/moneta/adapters/couch/adapter_couch_spec.rb +7 -0
- data/spec/moneta/adapters/couch/standard_couch_spec.rb +9 -0
- data/spec/moneta/adapters/couch/standard_couch_with_expires_spec.rb +13 -0
- data/spec/moneta/adapters/datamapper/adapter_datamapper_spec.rb +43 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_spec.rb +21 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_expires_spec.rb +26 -0
- data/spec/moneta/adapters/datamapper/standard_datamapper_with_repository_spec.rb +22 -0
- data/spec/moneta/adapters/daybreak/adapter_daybreak_spec.rb +7 -0
- data/spec/moneta/adapters/daybreak/standard_daybreak_spec.rb +7 -0
- data/spec/moneta/adapters/daybreak/standard_daybreak_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/dbm/adapter_dbm_spec.rb +7 -0
- data/spec/moneta/adapters/dbm/standard_dbm_spec.rb +7 -0
- data/spec/moneta/adapters/dbm/standard_dbm_with_expires_spec.rb +12 -0
- data/spec/moneta/adapters/file/adapter_file_spec.rb +7 -0
- data/spec/moneta/adapters/file/standard_file_spec.rb +7 -0
- data/spec/moneta/adapters/file/standard_file_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/fog/adapter_fog_spec.rb +16 -0
- data/spec/moneta/adapters/fog/standard_fog_spec.rb +15 -0
- data/spec/moneta/adapters/fog/standard_fog_with_expires_spec.rb +20 -0
- data/spec/moneta/adapters/gdbm/adapter_gdbm_spec.rb +7 -0
- data/spec/moneta/adapters/gdbm/standard_gdbm_spec.rb +7 -0
- data/spec/moneta/adapters/gdbm/standard_gdbm_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/hashfile/standard_hashfile_spec.rb +7 -0
- data/spec/moneta/adapters/hashfile/standard_hashfile_with_expires_spec.rb +12 -0
- data/spec/moneta/adapters/hbase/adapter_hbase_spec.rb +7 -0
- data/spec/moneta/adapters/hbase/standard_hbase_spec.rb +4 -0
- data/spec/moneta/adapters/hbase/standard_hbase_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/kyotocabinet/adapter_kyotocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/kyotocabinet/standard_kyotocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/kyotocabinet/standard_kyotocabinet_with_expires_spec.rb +14 -0
- data/spec/moneta/adapters/leveldb/adapter_leveldb_spec.rb +7 -0
- data/spec/moneta/adapters/leveldb/standard_leveldb_spec.rb +7 -0
- data/spec/moneta/adapters/leveldb/standard_leveldb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/lmdb/adapter_lmdb_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/adapter_lmdb_with_db_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/standard_lmdb_spec.rb +7 -0
- data/spec/moneta/adapters/lmdb/standard_lmdb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/localmemcache/adapter_localmemcache_spec.rb +7 -0
- data/spec/moneta/adapters/localmemcache/standard_localmemcache_spec.rb +7 -0
- data/spec/moneta/adapters/localmemcache/standard_localmemcache_with_expires_spec.rb +11 -0
- data/spec/moneta/{adapter_lruhash_spec.rb → adapters/lruhash/adapter_lruhash_spec.rb} +3 -25
- data/spec/moneta/adapters/lruhash/standard_lruhash_spec.rb +4 -0
- data/spec/moneta/adapters/lruhash/standard_lruhash_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/memcached/adapter_memcached_spec.rb +13 -0
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/dalli/adapter_memcached_dalli_with_default_expires_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/dalli/standard_memcached_dalli_spec.rb +11 -0
- data/spec/moneta/adapters/memcached/helper.rb +20 -0
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/native/adapter_memcached_native_with_default_expires_spec.rb +15 -0
- data/spec/moneta/adapters/memcached/native/standard_memcached_native_spec.rb +11 -0
- data/spec/moneta/adapters/memcached/standard_memcached_spec.rb +17 -0
- data/spec/moneta/adapters/memory/adapter_memory_spec.rb +7 -0
- data/spec/moneta/adapters/memory/standard_memory_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_compress_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_key_serializer_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_serializer_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_json_value_serializer_spec.rb +9 -0
- data/spec/moneta/adapters/memory/standard_memory_with_prefix_spec.rb +4 -0
- data/spec/moneta/adapters/memory/standard_memory_with_snappy_compress_spec.rb +9 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_moped_spec.rb +25 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_moped_with_default_expires_spec.rb +12 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_official_spec.rb +25 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_official_with_default_expires_spec.rb +12 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_spec.rb +11 -0
- data/spec/moneta/adapters/mongo/adapter_mongo_with_default_expires_spec.rb +12 -0
- data/spec/moneta/adapters/mongo/standard_mongo_moped_spec.rb +7 -0
- data/spec/moneta/adapters/mongo/standard_mongo_official_spec.rb +7 -0
- data/spec/moneta/adapters/mongo/standard_mongo_spec.rb +7 -0
- data/spec/moneta/adapters/null/null_adapter_spec.rb +7 -0
- data/spec/moneta/adapters/null/standard_null_spec.rb +4 -0
- data/spec/moneta/adapters/pstore/adapter_pstore_spec.rb +7 -0
- data/spec/moneta/adapters/pstore/standard_pstore_spec.rb +9 -0
- data/spec/moneta/adapters/pstore/standard_pstore_with_expires_spec.rb +13 -0
- data/spec/moneta/adapters/redis/adapter_redis_spec.rb +10 -0
- data/spec/moneta/adapters/redis/adapter_redis_with_default_expires_spec.rb +10 -0
- data/spec/moneta/adapters/redis/standard_redis_spec.rb +7 -0
- data/spec/moneta/adapters/restclient/adapter_restclient_spec.rb +11 -0
- data/spec/moneta/adapters/restclient/standard_restclient_spec.rb +10 -0
- data/spec/moneta/adapters/riak/adapter_riak_spec.rb +14 -0
- data/spec/moneta/adapters/riak/standard_riak_spec.rb +10 -0
- data/spec/moneta/adapters/riak/standard_riak_with_expires_spec.rb +10 -0
- data/spec/moneta/adapters/sdbm/adapter_sdbm_spec.rb +7 -0
- data/spec/moneta/adapters/sdbm/standard_sdbm_spec.rb +7 -0
- data/spec/moneta/adapters/sdbm/standard_sdbm_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/sequel/adapter_sequel_spec.rb +181 -0
- data/spec/moneta/adapters/sequel/standard_sequel_spec.rb +14 -0
- data/spec/moneta/adapters/sequel/standard_sequel_with_expires_spec.rb +19 -0
- data/spec/moneta/adapters/sqlite/adapter_sqlite_spec.rb +7 -0
- data/spec/moneta/adapters/sqlite/standard_sqlite_spec.rb +7 -0
- data/spec/moneta/adapters/sqlite/standard_sqlite_with_expires_spec.rb +15 -0
- data/spec/moneta/adapters/tdb/adapter_tdb_spec.rb +7 -0
- data/spec/moneta/adapters/tdb/standard_tdb_spec.rb +7 -0
- data/spec/moneta/adapters/tdb/standard_tdb_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/tokyocabinet/adapter_tokyocabinet_bdb_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/adapter_tokyocabinet_hdb_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/standard_tokyocabinet_spec.rb +7 -0
- data/spec/moneta/adapters/tokyocabinet/standard_tokyocabinet_with_expires_spec.rb +11 -0
- data/spec/moneta/adapters/tokyotyrant/adapter_tokyotyrant_spec.rb +7 -0
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_spec.rb +4 -0
- data/spec/moneta/adapters/tokyotyrant/standard_tokyotyrant_with_expires_spec.rb +8 -0
- data/spec/moneta/adapters/yaml/adapter_yaml_spec.rb +7 -0
- data/spec/moneta/adapters/yaml/standard_yaml_spec.rb +9 -0
- data/spec/moneta/adapters/yaml/standard_yaml_with_expires_spec.rb +13 -0
- data/spec/moneta/builder_spec.rb +0 -1
- data/spec/moneta/mutex_spec.rb +6 -23
- data/spec/moneta/proxies/cache/cache_file_memory_spec.rb +24 -0
- data/spec/moneta/proxies/cache/cache_memory_null_spec.rb +12 -0
- data/spec/moneta/proxies/expires/expires_file_spec.rb +28 -0
- data/spec/moneta/proxies/expires/expires_memory_spec.rb +15 -0
- data/spec/moneta/proxies/expires/expires_memory_with_default_expires_spec.rb +16 -0
- data/spec/moneta/proxies/lock/lock_spec.rb +10 -0
- data/spec/moneta/{optionmerger_spec.rb → proxies/optionmerger/optionmerger_spec.rb} +2 -18
- data/spec/moneta/proxies/pool/pool_spec.rb +12 -0
- data/spec/moneta/proxies/proxy/proxy_expires_memory_spec.rb +16 -0
- data/spec/moneta/proxies/proxy/proxy_redis_spec.rb +13 -0
- data/spec/moneta/proxies/shared/shared_tcp_spec.rb +49 -0
- data/spec/moneta/proxies/shared/shared_unix_spec.rb +48 -0
- data/spec/moneta/proxies/transformer/transformer_bencode_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_bert_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_bson_spec.rb +23 -0
- data/spec/moneta/proxies/transformer/transformer_bzip2_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_json_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_key_inspect_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_marshal_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_to_s_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_key_yaml_spec.rb +17 -0
- data/spec/moneta/proxies/transformer/transformer_lz4_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_lzma_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_lzo_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_base64_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city128_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city32_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_city64_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_escape_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_hex_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_hmac_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_md5_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_md5_spread_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_prefix_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_qp_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_rmd160_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha1_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha256_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha384_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_sha512_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_truncate_spec.rb +15 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_urlsafe_base64_spec.rb +20 -0
- data/spec/moneta/proxies/transformer/transformer_marshal_uuencode_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_msgpack_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_ox_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_php_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_quicklz_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_snappy_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_tnet_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_value_marshal_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_value_yaml_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_yaml_spec.rb +19 -0
- data/spec/moneta/proxies/transformer/transformer_zlib_spec.rb +19 -0
- data/spec/moneta/proxies/weak_create/weak_create_spec.rb +21 -0
- data/spec/moneta/proxies/weak_each_key/weak_each_key_spec.rb +24 -0
- data/spec/moneta/proxies/weak_increment/weak_increment_spec.rb +21 -0
- data/spec/moneta/semaphore_spec.rb +6 -23
- data/spec/moneta/stack_file_memory_spec.rb +5 -29
- data/spec/moneta/stack_memory_file_spec.rb +5 -31
- data/spec/quality_spec.rb +1 -1
- data/{spec → test}/action_dispatch/fixtures/session_autoload_test/foo.rb +0 -0
- data/{spec/action_dispatch/session_moneta_store_spec.rb → test/action_dispatch/session_moneta_store_test.rb} +13 -5
- metadata +415 -355
- data/script/generate-specs +0 -2696
- data/spec/moneta/adapter_activerecord_exisiting_connection_spec.rb +0 -36
- data/spec/moneta/adapter_activerecord_spec.rb +0 -65
- data/spec/moneta/adapter_cassandra_spec.rb +0 -33
- data/spec/moneta/adapter_cassandra_with_default_expires_spec.rb +0 -34
- data/spec/moneta/adapter_client_spec.rb +0 -35
- data/spec/moneta/adapter_cookie_spec.rb +0 -30
- data/spec/moneta/adapter_couch_spec.rb +0 -36
- data/spec/moneta/adapter_datamapper_spec.rb +0 -64
- data/spec/moneta/adapter_daybreak_spec.rb +0 -31
- data/spec/moneta/adapter_dbm_spec.rb +0 -31
- data/spec/moneta/adapter_file_spec.rb +0 -34
- data/spec/moneta/adapter_fog_spec.rb +0 -37
- data/spec/moneta/adapter_gdbm_spec.rb +0 -31
- data/spec/moneta/adapter_hbase_spec.rb +0 -33
- data/spec/moneta/adapter_kyotocabinet_spec.rb +0 -31
- data/spec/moneta/adapter_leveldb_spec.rb +0 -31
- data/spec/moneta/adapter_lmdb_spec.rb +0 -32
- data/spec/moneta/adapter_lmdb_with_db_spec.rb +0 -32
- data/spec/moneta/adapter_localmemcache_spec.rb +0 -32
- data/spec/moneta/adapter_memcached_dalli_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_dalli_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memcached_native_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_native_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memcached_spec.rb +0 -36
- data/spec/moneta/adapter_memcached_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_memory_spec.rb +0 -184
- data/spec/moneta/adapter_mongo_moped_spec.rb +0 -64
- data/spec/moneta/adapter_mongo_moped_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_mongo_official_spec.rb +0 -64
- data/spec/moneta/adapter_mongo_official_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_mongo_spec.rb +0 -51
- data/spec/moneta/adapter_mongo_with_default_expires_spec.rb +0 -53
- data/spec/moneta/adapter_pstore_spec.rb +0 -250
- data/spec/moneta/adapter_redis_spec.rb +0 -36
- data/spec/moneta/adapter_redis_with_default_expires_spec.rb +0 -37
- data/spec/moneta/adapter_restclient_spec.rb +0 -33
- data/spec/moneta/adapter_riak_spec.rb +0 -36
- data/spec/moneta/adapter_sdbm_spec.rb +0 -30
- data/spec/moneta/adapter_sequel_spec.rb +0 -34
- data/spec/moneta/adapter_sqlite_spec.rb +0 -32
- data/spec/moneta/adapter_tdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyocabinet_bdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyocabinet_hdb_spec.rb +0 -31
- data/spec/moneta/adapter_tokyotyrant_spec.rb +0 -34
- data/spec/moneta/adapter_yaml_spec.rb +0 -57
- data/spec/moneta/cache_file_memory_spec.rb +0 -50
- data/spec/moneta/cache_memory_null_spec.rb +0 -35
- data/spec/moneta/expires_file_spec.rb +0 -78
- data/spec/moneta/expires_memory_spec.rb +0 -189
- data/spec/moneta/expires_memory_with_default_expires_spec.rb +0 -190
- data/spec/moneta/lock_spec.rb +0 -187
- data/spec/moneta/null_adapter_spec.rb +0 -86
- data/spec/moneta/pool_spec.rb +0 -38
- data/spec/moneta/proxy_expires_memory_spec.rb +0 -191
- data/spec/moneta/proxy_redis_spec.rb +0 -40
- data/spec/moneta/shared_tcp_spec.rb +0 -46
- data/spec/moneta/shared_unix_spec.rb +0 -46
- data/spec/moneta/standard_activerecord_spec.rb +0 -253
- data/spec/moneta/standard_activerecord_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_cassandra_spec.rb +0 -252
- data/spec/moneta/standard_client_tcp_spec.rb +0 -269
- data/spec/moneta/standard_client_unix_spec.rb +0 -254
- data/spec/moneta/standard_couch_spec.rb +0 -252
- data/spec/moneta/standard_couch_with_expires_spec.rb +0 -254
- data/spec/moneta/standard_datamapper_spec.rb +0 -254
- data/spec/moneta/standard_datamapper_with_expires_spec.rb +0 -256
- data/spec/moneta/standard_datamapper_with_repository_spec.rb +0 -254
- data/spec/moneta/standard_daybreak_spec.rb +0 -250
- data/spec/moneta/standard_daybreak_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_dbm_spec.rb +0 -250
- data/spec/moneta/standard_dbm_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_file_spec.rb +0 -253
- data/spec/moneta/standard_file_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_fog_spec.rb +0 -256
- data/spec/moneta/standard_fog_with_expires_spec.rb +0 -258
- data/spec/moneta/standard_gdbm_spec.rb +0 -250
- data/spec/moneta/standard_gdbm_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_hashfile_spec.rb +0 -253
- data/spec/moneta/standard_hashfile_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_hbase_spec.rb +0 -252
- data/spec/moneta/standard_hbase_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_kyotocabinet_spec.rb +0 -250
- data/spec/moneta/standard_kyotocabinet_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_leveldb_spec.rb +0 -250
- data/spec/moneta/standard_leveldb_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_lmdb_spec.rb +0 -251
- data/spec/moneta/standard_lmdb_with_expires_spec.rb +0 -253
- data/spec/moneta/standard_localmemcache_spec.rb +0 -251
- data/spec/moneta/standard_localmemcache_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_lruhash_spec.rb +0 -187
- data/spec/moneta/standard_lruhash_with_expires_spec.rb +0 -189
- data/spec/moneta/standard_memcached_dalli_spec.rb +0 -255
- data/spec/moneta/standard_memcached_native_spec.rb +0 -255
- data/spec/moneta/standard_memcached_spec.rb +0 -255
- data/spec/moneta/standard_memory_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_compress_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_expires_spec.rb +0 -189
- data/spec/moneta/standard_memory_with_json_key_serializer_spec.rb +0 -86
- data/spec/moneta/standard_memory_with_json_serializer_spec.rb +0 -49
- data/spec/moneta/standard_memory_with_json_value_serializer_spec.rb +0 -90
- data/spec/moneta/standard_memory_with_prefix_spec.rb +0 -187
- data/spec/moneta/standard_memory_with_snappy_compress_spec.rb +0 -187
- data/spec/moneta/standard_mongo_moped_spec.rb +0 -255
- data/spec/moneta/standard_mongo_official_spec.rb +0 -255
- data/spec/moneta/standard_mongo_spec.rb +0 -255
- data/spec/moneta/standard_null_spec.rb +0 -120
- data/spec/moneta/standard_pstore_spec.rb +0 -253
- data/spec/moneta/standard_pstore_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_redis_spec.rb +0 -255
- data/spec/moneta/standard_restclient_spec.rb +0 -252
- data/spec/moneta/standard_riak_spec.rb +0 -255
- data/spec/moneta/standard_riak_with_expires_spec.rb +0 -256
- data/spec/moneta/standard_sdbm_spec.rb +0 -249
- data/spec/moneta/standard_sdbm_with_expires_spec.rb +0 -251
- data/spec/moneta/standard_sequel_spec.rb +0 -253
- data/spec/moneta/standard_sequel_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_sqlite_spec.rb +0 -251
- data/spec/moneta/standard_sqlite_with_expires_spec.rb +0 -253
- data/spec/moneta/standard_tdb_spec.rb +0 -250
- data/spec/moneta/standard_tdb_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_tokyocabinet_spec.rb +0 -250
- data/spec/moneta/standard_tokyocabinet_with_expires_spec.rb +0 -252
- data/spec/moneta/standard_tokyotyrant_spec.rb +0 -253
- data/spec/moneta/standard_tokyotyrant_with_expires_spec.rb +0 -255
- data/spec/moneta/standard_yaml_spec.rb +0 -250
- data/spec/moneta/standard_yaml_with_expires_spec.rb +0 -252
- data/spec/moneta/transformer_bencode_spec.rb +0 -55
- data/spec/moneta/transformer_bert_spec.rb +0 -55
- data/spec/moneta/transformer_bson_spec.rb +0 -60
- data/spec/moneta/transformer_bzip2_spec.rb +0 -55
- data/spec/moneta/transformer_json_spec.rb +0 -55
- data/spec/moneta/transformer_key_inspect_spec.rb +0 -91
- data/spec/moneta/transformer_key_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_key_to_s_spec.rb +0 -91
- data/spec/moneta/transformer_key_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_lz4_spec.rb +0 -55
- data/spec/moneta/transformer_lzma_spec.rb +0 -55
- data/spec/moneta/transformer_lzo_spec.rb +0 -55
- data/spec/moneta/transformer_marshal_base64_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city128_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city32_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_city64_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_escape_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_hex_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_hmac_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_md5_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_md5_spread_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_prefix_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_qp_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_rmd160_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha1_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha256_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha384_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_sha512_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_marshal_truncate_spec.rb +0 -194
- data/spec/moneta/transformer_marshal_uuencode_spec.rb +0 -194
- data/spec/moneta/transformer_msgpack_spec.rb +0 -55
- data/spec/moneta/transformer_ox_spec.rb +0 -191
- data/spec/moneta/transformer_php_spec.rb +0 -55
- data/spec/moneta/transformer_quicklz_spec.rb +0 -55
- data/spec/moneta/transformer_snappy_spec.rb +0 -55
- data/spec/moneta/transformer_tnet_spec.rb +0 -55
- data/spec/moneta/transformer_value_marshal_spec.rb +0 -191
- data/spec/moneta/transformer_value_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_yaml_spec.rb +0 -191
- data/spec/moneta/transformer_zlib_spec.rb +0 -55
- data/spec/moneta/weak_create_spec.rb +0 -41
- data/spec/moneta/weak_increment_spec.rb +0 -41
- data/spec/monetaspecs.rb +0 -51267
data/lib/moneta/pool.rb
CHANGED
@@ -14,7 +14,6 @@ module Moneta
|
|
14
14
|
#
|
15
15
|
# @api public
|
16
16
|
class Pool < Wrapper
|
17
|
-
# @param [Moneta store] adapter The underlying store
|
18
17
|
# @param [Hash] options
|
19
18
|
# @option options [String] :mutex (::Mutex.new) Mutex object
|
20
19
|
def initialize(options = {}, &block)
|
@@ -39,7 +38,19 @@ module Moneta
|
|
39
38
|
Thread.current[@id]
|
40
39
|
end
|
41
40
|
|
42
|
-
def wrap(*args)
|
41
|
+
def wrap(*args, &block)
|
42
|
+
if checked_out?
|
43
|
+
yield
|
44
|
+
else
|
45
|
+
check_out!(&block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def checked_out?
|
50
|
+
Thread.current.key?(@id) && Thread.current[@id] != nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_out!
|
43
54
|
store = Thread.current[@id] = pop
|
44
55
|
yield
|
45
56
|
ensure
|
@@ -48,13 +59,11 @@ module Moneta
|
|
48
59
|
end
|
49
60
|
|
50
61
|
def pop
|
51
|
-
|
62
|
+
unless store = @mutex.synchronize { @pool.pop }
|
52
63
|
store = @builder.build.last
|
53
64
|
@mutex.synchronize { @all << store }
|
54
|
-
store
|
55
|
-
else
|
56
|
-
@mutex.synchronize { @pool.pop }
|
57
65
|
end
|
66
|
+
store
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
data/lib/moneta/proxy.rb
CHANGED
@@ -17,6 +17,16 @@ module Moneta
|
|
17
17
|
adapter.key?(key, options)
|
18
18
|
end
|
19
19
|
|
20
|
+
# (see Defaults#each_key)
|
21
|
+
def each_key(&block)
|
22
|
+
raise NotImplementedError, "each_key is not supported on this proxy" \
|
23
|
+
unless supports? :each_key
|
24
|
+
|
25
|
+
return enum_for(:each_key) unless block_given?
|
26
|
+
adapter.each_key(&block)
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
20
30
|
# (see Defaults#increment)
|
21
31
|
def increment(key, amount = 1, options = {})
|
22
32
|
adapter.increment(key, amount, options)
|
@@ -85,9 +95,43 @@ module Moneta
|
|
85
95
|
self
|
86
96
|
end
|
87
97
|
|
88
|
-
# (see
|
98
|
+
# (see Defaults#values_at)
|
99
|
+
def values_at(*keys, **options)
|
100
|
+
adapter.values_at(*keys, **options)
|
101
|
+
end
|
102
|
+
|
103
|
+
# (see Defaults#fetch_values)
|
104
|
+
def fetch_values(*keys, **options, &defaults)
|
105
|
+
adapter.fetch_values(*keys, **options, &defaults)
|
106
|
+
end
|
107
|
+
|
108
|
+
# (see Defaults#slice)
|
109
|
+
def slice(*keys, **options)
|
110
|
+
adapter.slice(*keys, **options)
|
111
|
+
end
|
112
|
+
|
113
|
+
# (see Defaults#merge!)
|
114
|
+
def merge!(pairs, options = {}, &block)
|
115
|
+
adapter.merge!(pairs, options, &block)
|
116
|
+
self
|
117
|
+
end
|
118
|
+
|
119
|
+
# (see Defaults#features)
|
89
120
|
def features
|
90
|
-
@features ||= (self.class.features
|
121
|
+
@features ||= (self.class.features | adapter.features - self.class.features_mask).freeze
|
122
|
+
end
|
123
|
+
|
124
|
+
class << self
|
125
|
+
# @api private
|
126
|
+
def features_mask
|
127
|
+
@features_mask ||= [].freeze
|
128
|
+
end
|
129
|
+
|
130
|
+
# (see Defaults::ClassMethods#not_supports)
|
131
|
+
def not_supports *features
|
132
|
+
@features_mask = (self.features_mask | features).freeze
|
133
|
+
super
|
134
|
+
end
|
91
135
|
end
|
92
136
|
end
|
93
137
|
end
|
data/lib/moneta/server.rb
CHANGED
@@ -35,6 +35,7 @@ module Moneta
|
|
35
35
|
end
|
36
36
|
ensure
|
37
37
|
File.unlink(@socket) if @socket
|
38
|
+
@ios.each{ |io| io.close rescue nil }
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -99,8 +100,11 @@ module Moneta
|
|
99
100
|
buffer.slice!(0, 4)
|
100
101
|
method, *args = Marshal.load(buffer.slice!(0, size))
|
101
102
|
case method
|
102
|
-
when :key?, :load, :delete, :increment, :create
|
103
|
+
when :key?, :load, :delete, :increment, :create
|
103
104
|
io.write(pack @store.send(method, *args))
|
105
|
+
when :features
|
106
|
+
# all features except each_key are supported
|
107
|
+
io.write(pack(@store.features - [:each_key]))
|
104
108
|
when :store, :clear
|
105
109
|
@store.send(method, *args)
|
106
110
|
io.write(@nil ||= pack(nil))
|
data/lib/moneta/shared.rb
CHANGED
@@ -11,6 +11,8 @@ module Moneta
|
|
11
11
|
#
|
12
12
|
# @api public
|
13
13
|
class Shared < Wrapper
|
14
|
+
not_supports :each_key
|
15
|
+
|
14
16
|
# @param [Hash] options
|
15
17
|
# @option options [Integer] :port (9000) TCP port
|
16
18
|
# @option options [String] :host Server hostname
|
@@ -18,6 +20,7 @@ module Moneta
|
|
18
20
|
def initialize(options = {}, &block)
|
19
21
|
@options = options
|
20
22
|
@builder = Builder.new(&block)
|
23
|
+
@connect_lock = ::Mutex.new
|
21
24
|
end
|
22
25
|
|
23
26
|
# (see Proxy#close)
|
@@ -38,10 +41,17 @@ module Moneta
|
|
38
41
|
def wrap(*args)
|
39
42
|
connect
|
40
43
|
yield
|
44
|
+
rescue Errno::ECONNRESET, Errno::EPIPE, IOError, SystemCallError
|
45
|
+
@connect_lock.synchronize{ close unless @server }
|
46
|
+
tries ||= 0
|
47
|
+
(tries += 1) < 3 ? retry : raise
|
41
48
|
end
|
42
49
|
|
43
50
|
def connect
|
44
|
-
|
51
|
+
return if @adapter
|
52
|
+
@connect_lock.synchronize do
|
53
|
+
@adapter ||= Adapters::Client.new(@options)
|
54
|
+
end
|
45
55
|
rescue Errno::ECONNREFUSED, Errno::ENOENT => ex
|
46
56
|
start_server
|
47
57
|
tries ||= 0
|
@@ -52,16 +62,22 @@ module Moneta
|
|
52
62
|
# TODO: Implement this using forking (MRI) and threading (JRuby)
|
53
63
|
# to get maximal performance
|
54
64
|
def start_server
|
55
|
-
@
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
@connect_lock.synchronize do
|
66
|
+
begin
|
67
|
+
raise "Adapter already set" if @adapter
|
68
|
+
@adapter = Lock.new(@builder.build.last)
|
69
|
+
raise "Server already set" if @server
|
70
|
+
@server = Server.new(@adapter, @options)
|
71
|
+
@thread = Thread.new { @server.run }
|
72
|
+
sleep 0.1 until @server.running?
|
73
|
+
rescue => ex
|
74
|
+
@adapter.close if @adapter
|
75
|
+
@adapter = nil
|
76
|
+
@server = nil
|
77
|
+
@thread = nil
|
78
|
+
warn "Moneta::Shared - Failed to start server: #{ex.message}"
|
79
|
+
end
|
80
|
+
end
|
65
81
|
end
|
66
82
|
end
|
67
83
|
end
|
data/lib/moneta/stack.rb
CHANGED
data/lib/moneta/synchronize.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Moneta
|
2
2
|
# Base class for {Mutex} and {Semaphore}
|
3
|
-
# @
|
3
|
+
# @abstract
|
4
4
|
class SynchronizePrimitive
|
5
5
|
# Synchronize block
|
6
6
|
#
|
@@ -16,7 +16,6 @@ module Moneta
|
|
16
16
|
|
17
17
|
# Try to enter critical section (nonblocking)
|
18
18
|
#
|
19
|
-
# @api public
|
20
19
|
# @return [Boolean] true if the lock was acquired
|
21
20
|
def try_enter
|
22
21
|
raise 'Already locked' if @locked
|
@@ -26,7 +25,6 @@ module Moneta
|
|
26
25
|
|
27
26
|
# Enter critical section (blocking)
|
28
27
|
#
|
29
|
-
# @api public
|
30
28
|
# @param [Number] timeout Maximum time to wait
|
31
29
|
# @param [Number] wait Sleep time between tries to acquire lock
|
32
30
|
# @return [Boolean] true if the lock was aquired
|
@@ -41,8 +39,6 @@ module Moneta
|
|
41
39
|
alias_method :lock, :enter
|
42
40
|
|
43
41
|
# Leave critical section
|
44
|
-
#
|
45
|
-
# @api public
|
46
42
|
def leave
|
47
43
|
raise 'Not locked' unless @locked
|
48
44
|
leave_primitive
|
@@ -52,8 +48,6 @@ module Moneta
|
|
52
48
|
alias_method :unlock, :leave
|
53
49
|
|
54
50
|
# Is the lock acquired?
|
55
|
-
#
|
56
|
-
# @api public
|
57
51
|
def locked?
|
58
52
|
@locked
|
59
53
|
end
|
@@ -101,7 +95,7 @@ module Moneta
|
|
101
95
|
class Semaphore < SynchronizePrimitive
|
102
96
|
# @param [Moneta store] store The store we want to lock
|
103
97
|
# @param [Object] counter Key of the counter entry
|
104
|
-
# @param [
|
98
|
+
# @param [Integer] max Maximum number of threads which are allowed to enter the critical section
|
105
99
|
def initialize(store, counter, max = 1)
|
106
100
|
raise 'Store must support feature :increment' unless store.supports?(:increment)
|
107
101
|
@store, @counter, @max = store, counter, max
|
data/lib/moneta/transformer.rb
CHANGED
@@ -79,6 +79,8 @@ module Moneta
|
|
79
79
|
|
80
80
|
def compile_key_transformer(klass, key, key_opts)
|
81
81
|
klass.class_eval <<-end_eval, __FILE__, __LINE__
|
82
|
+
not_supports :each_key
|
83
|
+
|
82
84
|
def key?(key, options = {})
|
83
85
|
@adapter.key?(#{key}, #{without key_opts})
|
84
86
|
end
|
@@ -97,6 +99,36 @@ module Moneta
|
|
97
99
|
def create(key, value, options = {})
|
98
100
|
@adapter.create(#{key}, value, #{without :raw, key_opts})
|
99
101
|
end
|
102
|
+
def values_at(*keys, **options)
|
103
|
+
t_keys = keys.map { |key| #{key} }
|
104
|
+
@adapter.values_at(*t_keys, **#{without :raw, key_opts})
|
105
|
+
end
|
106
|
+
def fetch_values(*keys, **options)
|
107
|
+
t_keys = keys.map { |key| #{key} }
|
108
|
+
|
109
|
+
block = if block_given?
|
110
|
+
key_lookup = Hash[t_keys.zip(keys)]
|
111
|
+
lambda { |t_key| yield key_lookup[t_key] }
|
112
|
+
end
|
113
|
+
@adapter.fetch_values(*t_keys, **#{without :raw, key_opts}, &block)
|
114
|
+
end
|
115
|
+
def slice(*keys, **options)
|
116
|
+
t_keys = keys.map { |key| #{key} }
|
117
|
+
key_lookup = Hash[t_keys.zip(keys)]
|
118
|
+
@adapter.slice(*t_keys, **#{without :raw, key_opts}).map do |key, value|
|
119
|
+
[key_lookup[key], value]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
def merge!(pairs, options = {})
|
123
|
+
keys, values = pairs.to_a.transpose
|
124
|
+
t_keys = keys.map { |key| #{key} }
|
125
|
+
block = if block_given?
|
126
|
+
key_lookup = Hash[t_keys.zip(keys)]
|
127
|
+
lambda { |k, old, new| yield(key_lookup[k], old, new) }
|
128
|
+
end
|
129
|
+
@adapter.merge!(t_keys.zip(values), #{without :raw, key_opts}, &block)
|
130
|
+
self
|
131
|
+
end
|
100
132
|
end_eval
|
101
133
|
end
|
102
134
|
|
@@ -117,11 +149,61 @@ module Moneta
|
|
117
149
|
def create(key, value, options = {})
|
118
150
|
@adapter.create(key, options[:raw] ? value : #{dump}, #{without :raw, dump_opts})
|
119
151
|
end
|
152
|
+
def values_at(*keys, **options)
|
153
|
+
values = @adapter.values_at(*keys, **#{without :raw, load_opts})
|
154
|
+
values.map do |value|
|
155
|
+
value && !options[:raw] ? #{load} : value
|
156
|
+
end
|
157
|
+
end
|
158
|
+
def fetch_values(*keys, **options, &orig_block)
|
159
|
+
substituted = {}
|
160
|
+
block = if block_given?
|
161
|
+
lambda { |key| substituted[key] = true; yield key }
|
162
|
+
end
|
163
|
+
|
164
|
+
values = @adapter.fetch_values(*keys, **#{without :raw, load_opts}, &block)
|
165
|
+
if options[:raw]
|
166
|
+
values
|
167
|
+
else
|
168
|
+
keys.map(&substituted.method(:key?)).zip(values).map do |substituted, value|
|
169
|
+
if substituted || !value
|
170
|
+
value
|
171
|
+
else
|
172
|
+
#{load}
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
def slice(*keys, **options)
|
178
|
+
@adapter.slice(*keys, **#{without :raw, load_opts}).map do |key, value|
|
179
|
+
[key, value && !options[:raw] ? #{load} : value]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
def merge!(pairs, options = {}, &orig_block)
|
183
|
+
block = if block_given?
|
184
|
+
if options[:raw]
|
185
|
+
orig_block
|
186
|
+
else
|
187
|
+
lambda do |k, old_val, new_val|
|
188
|
+
value = old_val; old_val = #{load}
|
189
|
+
value = new_val; new_val = #{load}
|
190
|
+
value = yield(k, old_val, new_val)
|
191
|
+
#{dump}
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
t_pairs = options[:raw] ? pairs : pairs.map { |key, value| [key, #{dump}] }
|
197
|
+
@adapter.merge!(t_pairs, #{without :raw, dump_opts}, &block)
|
198
|
+
self
|
199
|
+
end
|
120
200
|
end_eval
|
121
201
|
end
|
122
202
|
|
123
203
|
def compile_key_value_transformer(klass, key, key_opts, load, load_opts, dump, dump_opts)
|
124
204
|
klass.class_eval <<-end_eval, __FILE__, __LINE__
|
205
|
+
not_supports :each_key
|
206
|
+
|
125
207
|
def key?(key, options = {})
|
126
208
|
@adapter.key?(#{key}, #{without key_opts})
|
127
209
|
end
|
@@ -143,6 +225,73 @@ module Moneta
|
|
143
225
|
def create(key, value, options = {})
|
144
226
|
@adapter.create(#{key}, options[:raw] ? value : #{dump}, #{without :raw, key_opts, dump_opts})
|
145
227
|
end
|
228
|
+
def values_at(*keys, **options)
|
229
|
+
t_keys = keys.map { |key| #{key} }
|
230
|
+
values = @adapter.values_at(*t_keys, **#{without :raw, key_opts, load_opts})
|
231
|
+
values.map do |value|
|
232
|
+
value && !options[:raw] ? #{load} : value
|
233
|
+
end
|
234
|
+
end
|
235
|
+
def fetch_values(*keys, **options)
|
236
|
+
t_keys = keys.map { |key| #{key} }
|
237
|
+
key_lookup = Hash[t_keys.zip(keys)]
|
238
|
+
substituted = {}
|
239
|
+
block = if block_given?
|
240
|
+
lambda do |t_key|
|
241
|
+
key = key_lookup[t_key]
|
242
|
+
substituted[key] = true
|
243
|
+
yield key
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
values = @adapter.fetch_values(*t_keys, **#{without :raw, key_opts, load_opts}, &block)
|
248
|
+
|
249
|
+
if options[:raw]
|
250
|
+
values
|
251
|
+
else
|
252
|
+
keys.map(&substituted.method(:key?)).zip(values).map do |substituted, value|
|
253
|
+
if substituted || !value
|
254
|
+
value
|
255
|
+
else
|
256
|
+
#{load}
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
def slice(*keys, **options)
|
262
|
+
t_keys = keys.map { |key| #{key} }
|
263
|
+
key_lookup = Hash[t_keys.zip(keys)]
|
264
|
+
@adapter.slice(*t_keys, **#{without :raw, key_opts, load_opts}).map do |key, value|
|
265
|
+
[key_lookup[key], value && !options[:raw] ? #{load} : value]
|
266
|
+
end
|
267
|
+
end
|
268
|
+
def merge!(pairs, options = {})
|
269
|
+
keys, values = pairs.to_a.transpose
|
270
|
+
t_keys = keys.map { |key| #{key} }
|
271
|
+
key_lookup = Hash[t_keys.zip(keys)]
|
272
|
+
|
273
|
+
block = if block_given?
|
274
|
+
if options[:raw]
|
275
|
+
lambda do |k, old_val, new_val|
|
276
|
+
yield(key_lookup[k], old_val, new_val)
|
277
|
+
end
|
278
|
+
else
|
279
|
+
lambda do |k, old_val, new_val|
|
280
|
+
value = old_val; old_val = #{load}
|
281
|
+
value = new_val; new_val = #{load}
|
282
|
+
value = yield(key_lookup[k], old_val, new_val)
|
283
|
+
#{dump}
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
t_pairs = if options[:raw]
|
288
|
+
t_keys.zip(values)
|
289
|
+
else
|
290
|
+
t_keys.zip(values.map { |value| #{dump} })
|
291
|
+
end
|
292
|
+
@adapter.merge!(t_pairs, #{without :raw, key_opts, dump_opts}, &block)
|
293
|
+
self
|
294
|
+
end
|
146
295
|
end_eval
|
147
296
|
end
|
148
297
|
|
@@ -181,8 +330,9 @@ module Moneta
|
|
181
330
|
end
|
182
331
|
|
183
332
|
def class_name(keys, values)
|
184
|
-
|
185
|
-
|
333
|
+
camel_case = lambda{ |sym| sym.to_s.split('_').map(&:capitalize).join }
|
334
|
+
(keys.empty? ? '' : keys.map(&camel_case).join + 'Key') +
|
335
|
+
(values.empty? ? '' : values.map(&camel_case).join + 'Value')
|
186
336
|
end
|
187
337
|
end
|
188
338
|
end
|
@@ -21,6 +21,8 @@ module Moneta
|
|
21
21
|
quicklz: [ :compress, '::QuickLZ.decompress(%s)', '::QuickLZ.compress(%s)', 'qlzruby' ],
|
22
22
|
zlib: [ :compress, '::Zlib::Inflate.inflate(%s)', '::Zlib::Deflate.deflate(%s)', 'zlib' ],
|
23
23
|
base64: [ :encode, "%s.unpack('m0').first", "[%s].pack('m0')" ],
|
24
|
+
urlsafe_base64: [
|
25
|
+
:encode, 'Base64.urlsafe_decode64(%s)', 'Base64.urlsafe_encode64(%s)', 'base64' ],
|
24
26
|
escape: [ :encode, 'Helper.unescape(%s)', 'Helper.escape(%s)' ],
|
25
27
|
hex: [ :encode, "[%s].pack('H*')", "%s.unpack('H*').first" ],
|
26
28
|
qp: [ :encode, "%s.unpack('M').first", "[%s].pack('M')" ],
|