juno 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -277
- data/juno.gemspec +6 -5
- data/lib/juno.rb +3 -122
- metadata +23 -307
- data/.gitignore +0 -6
- data/.travis.yml +0 -30
- data/Gemfile +0 -56
- data/LICENSE +0 -20
- data/Rakefile +0 -33
- data/SPEC.md +0 -71
- data/benchmarks/run.rb +0 -180
- data/lib/juno/adapters/activerecord.rb +0 -74
- data/lib/juno/adapters/cassandra.rb +0 -89
- data/lib/juno/adapters/cookie.rb +0 -35
- data/lib/juno/adapters/couch.rb +0 -57
- data/lib/juno/adapters/datamapper.rb +0 -76
- data/lib/juno/adapters/dbm.rb +0 -25
- data/lib/juno/adapters/file.rb +0 -60
- data/lib/juno/adapters/fog.rb +0 -51
- data/lib/juno/adapters/gdbm.rb +0 -25
- data/lib/juno/adapters/hbase.rb +0 -64
- data/lib/juno/adapters/leveldb.rb +0 -35
- data/lib/juno/adapters/localmemcache.rb +0 -26
- data/lib/juno/adapters/lruhash.rb +0 -83
- data/lib/juno/adapters/memcached.rb +0 -11
- data/lib/juno/adapters/memcached_dalli.rb +0 -51
- data/lib/juno/adapters/memcached_native.rb +0 -52
- data/lib/juno/adapters/memory.rb +0 -32
- data/lib/juno/adapters/mongo.rb +0 -50
- data/lib/juno/adapters/null.rb +0 -30
- data/lib/juno/adapters/pstore.rb +0 -58
- data/lib/juno/adapters/redis.rb +0 -56
- data/lib/juno/adapters/riak.rb +0 -57
- data/lib/juno/adapters/sdbm.rb +0 -35
- data/lib/juno/adapters/sequel.rb +0 -67
- data/lib/juno/adapters/sqlite.rb +0 -61
- data/lib/juno/adapters/tokyocabinet.rb +0 -41
- data/lib/juno/adapters/yaml.rb +0 -15
- data/lib/juno/base.rb +0 -62
- data/lib/juno/builder.rb +0 -39
- data/lib/juno/cache.rb +0 -78
- data/lib/juno/expires.rb +0 -47
- data/lib/juno/lock.rb +0 -44
- data/lib/juno/logger.rb +0 -86
- data/lib/juno/proxy.rb +0 -72
- data/lib/juno/stack.rb +0 -72
- data/lib/juno/transformer.rb +0 -176
- data/lib/juno/version.rb +0 -5
- data/lib/rack/cache/juno.rb +0 -93
- data/lib/rack/juno_cookies.rb +0 -64
- data/lib/rack/session/juno.rb +0 -63
- data/spec/generate.rb +0 -1068
- data/spec/helper.rb +0 -78
- data/spec/juno/adapter_activerecord_spec.rb +0 -27
- data/spec/juno/adapter_cassandra_spec.rb +0 -13
- data/spec/juno/adapter_cookie_spec.rb +0 -13
- data/spec/juno/adapter_couch_spec.rb +0 -13
- data/spec/juno/adapter_datamapper_spec.rb +0 -44
- data/spec/juno/adapter_dbm_spec.rb +0 -13
- data/spec/juno/adapter_file_spec.rb +0 -13
- data/spec/juno/adapter_fog_spec.rb +0 -18
- data/spec/juno/adapter_gdbm_spec.rb +0 -13
- data/spec/juno/adapter_hbase_spec.rb +0 -13
- data/spec/juno/adapter_leveldb_spec.rb +0 -13
- data/spec/juno/adapter_localmemcache_spec.rb +0 -13
- data/spec/juno/adapter_lruhash_spec.rb +0 -26
- data/spec/juno/adapter_memcached_dalli_spec.rb +0 -14
- data/spec/juno/adapter_memcached_native_spec.rb +0 -14
- data/spec/juno/adapter_memcached_spec.rb +0 -14
- data/spec/juno/adapter_memory_spec.rb +0 -34
- data/spec/juno/adapter_mongo_spec.rb +0 -13
- data/spec/juno/adapter_pstore_spec.rb +0 -16
- data/spec/juno/adapter_redis_spec.rb +0 -14
- data/spec/juno/adapter_riak_spec.rb +0 -17
- data/spec/juno/adapter_sdbm_spec.rb +0 -13
- data/spec/juno/adapter_sequel_spec.rb +0 -13
- data/spec/juno/adapter_sqlite_spec.rb +0 -13
- data/spec/juno/adapter_tokyocabinet_bdb_spec.rb +0 -13
- data/spec/juno/adapter_tokyocabinet_hdb_spec.rb +0 -13
- data/spec/juno/adapter_yaml_spec.rb +0 -16
- data/spec/juno/cache_file_memory_spec.rb +0 -29
- data/spec/juno/cache_memory_null_spec.rb +0 -18
- data/spec/juno/expires_file_spec.rb +0 -71
- data/spec/juno/expires_memory_spec.rb +0 -49
- data/spec/juno/lock_spec.rb +0 -37
- data/spec/juno/null_adapter_spec.rb +0 -22
- data/spec/juno/proxy_expires_memory_spec.rb +0 -51
- data/spec/juno/proxy_redis_spec.rb +0 -18
- data/spec/juno/simple_activerecord_spec.rb +0 -45
- data/spec/juno/simple_activerecord_with_expires_spec.rb +0 -46
- data/spec/juno/simple_cassandra_spec.rb +0 -46
- data/spec/juno/simple_couch_spec.rb +0 -45
- data/spec/juno/simple_couch_with_expires_spec.rb +0 -46
- data/spec/juno/simple_datamapper_spec.rb +0 -47
- data/spec/juno/simple_datamapper_with_expires_spec.rb +0 -48
- data/spec/juno/simple_datamapper_with_repository_spec.rb +0 -47
- data/spec/juno/simple_dbm_spec.rb +0 -45
- data/spec/juno/simple_dbm_with_expires_spec.rb +0 -46
- data/spec/juno/simple_file_spec.rb +0 -45
- data/spec/juno/simple_file_with_expires_spec.rb +0 -46
- data/spec/juno/simple_fog_spec.rb +0 -50
- data/spec/juno/simple_fog_with_expires_spec.rb +0 -52
- data/spec/juno/simple_gdbm_spec.rb +0 -45
- data/spec/juno/simple_gdbm_with_expires_spec.rb +0 -46
- data/spec/juno/simple_hashfile_spec.rb +0 -45
- data/spec/juno/simple_hashfile_with_expires_spec.rb +0 -46
- data/spec/juno/simple_hbase_spec.rb +0 -45
- data/spec/juno/simple_hbase_with_expires_spec.rb +0 -46
- data/spec/juno/simple_leveldb_spec.rb +0 -45
- data/spec/juno/simple_leveldb_with_expires_spec.rb +0 -46
- data/spec/juno/simple_localmemcache_spec.rb +0 -45
- data/spec/juno/simple_localmemcache_with_expires_spec.rb +0 -46
- data/spec/juno/simple_lruhash_spec.rb +0 -45
- data/spec/juno/simple_lruhash_with_expires_spec.rb +0 -46
- data/spec/juno/simple_memcached_dalli_spec.rb +0 -46
- data/spec/juno/simple_memcached_native_spec.rb +0 -46
- data/spec/juno/simple_memcached_spec.rb +0 -46
- data/spec/juno/simple_memory_spec.rb +0 -45
- data/spec/juno/simple_memory_with_compress_spec.rb +0 -45
- data/spec/juno/simple_memory_with_expires_spec.rb +0 -46
- data/spec/juno/simple_memory_with_json_key_serializer_spec.rb +0 -32
- data/spec/juno/simple_memory_with_json_md5_key_serializer_spec.rb +0 -32
- data/spec/juno/simple_memory_with_json_serializer_spec.rb +0 -22
- data/spec/juno/simple_memory_with_json_value_serializer_spec.rb +0 -29
- data/spec/juno/simple_memory_with_prefix_spec.rb +0 -45
- data/spec/juno/simple_memory_with_quicklz_compress_spec.rb +0 -45
- data/spec/juno/simple_mongo_spec.rb +0 -45
- data/spec/juno/simple_mongo_with_expires_spec.rb +0 -46
- data/spec/juno/simple_null_spec.rb +0 -32
- data/spec/juno/simple_pstore_spec.rb +0 -45
- data/spec/juno/simple_pstore_with_expires_spec.rb +0 -46
- data/spec/juno/simple_redis_spec.rb +0 -46
- data/spec/juno/simple_riak_spec.rb +0 -49
- data/spec/juno/simple_riak_with_expires_spec.rb +0 -50
- data/spec/juno/simple_sdbm_spec.rb +0 -45
- data/spec/juno/simple_sdbm_with_expires_spec.rb +0 -46
- data/spec/juno/simple_sequel_spec.rb +0 -45
- data/spec/juno/simple_sequel_with_expires_spec.rb +0 -46
- data/spec/juno/simple_sqlite_spec.rb +0 -45
- data/spec/juno/simple_sqlite_with_expires_spec.rb +0 -46
- data/spec/juno/simple_tokyocabinet_spec.rb +0 -45
- data/spec/juno/simple_tokyocabinet_with_expires_spec.rb +0 -46
- data/spec/juno/simple_yaml_spec.rb +0 -44
- data/spec/juno/simple_yaml_with_expires_spec.rb +0 -45
- data/spec/juno/stack_file_memory_spec.rb +0 -20
- data/spec/juno/stack_memory_file_spec.rb +0 -19
- data/spec/juno/transformer_bencode_spec.rb +0 -25
- data/spec/juno/transformer_bert_spec.rb +0 -25
- data/spec/juno/transformer_bson_spec.rb +0 -25
- data/spec/juno/transformer_bzip2_spec.rb +0 -22
- data/spec/juno/transformer_json_spec.rb +0 -25
- data/spec/juno/transformer_lzma_spec.rb +0 -22
- data/spec/juno/transformer_lzo_spec.rb +0 -22
- data/spec/juno/transformer_marshal_base64_spec.rb +0 -48
- data/spec/juno/transformer_marshal_escape_spec.rb +0 -48
- data/spec/juno/transformer_marshal_hmac_spec.rb +0 -48
- data/spec/juno/transformer_marshal_md5_spec.rb +0 -48
- data/spec/juno/transformer_marshal_md5_spread_spec.rb +0 -48
- data/spec/juno/transformer_marshal_prefix_spec.rb +0 -48
- data/spec/juno/transformer_marshal_rmd160_spec.rb +0 -48
- data/spec/juno/transformer_marshal_sha1_spec.rb +0 -48
- data/spec/juno/transformer_marshal_sha256_spec.rb +0 -48
- data/spec/juno/transformer_marshal_sha384_spec.rb +0 -48
- data/spec/juno/transformer_marshal_sha512_spec.rb +0 -48
- data/spec/juno/transformer_marshal_uuencode_spec.rb +0 -48
- data/spec/juno/transformer_msgpack_spec.rb +0 -25
- data/spec/juno/transformer_ox_spec.rb +0 -46
- data/spec/juno/transformer_quicklz_spec.rb +0 -22
- data/spec/juno/transformer_snappy_spec.rb +0 -22
- data/spec/juno/transformer_tnet_spec.rb +0 -25
- data/spec/juno/transformer_yaml_spec.rb +0 -46
- data/spec/juno/transformer_zlib_spec.rb +0 -22
- data/spec/junospecs.rb +0 -2284
- data/spec/rack/cache_juno_spec.rb +0 -355
- data/spec/rack/juno_cookies_spec.rb +0 -81
- data/spec/rack/session_juno_spec.rb +0 -305
data/lib/juno/adapters/riak.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# Copyright: 2011 TMX Credit
|
2
|
-
# Author: Potapov Sergey (aka Blake)
|
3
|
-
|
4
|
-
require 'riak'
|
5
|
-
|
6
|
-
module Juno
|
7
|
-
module Adapters
|
8
|
-
# Riak backend
|
9
|
-
# @api public
|
10
|
-
class Riak < Base
|
11
|
-
# Constructor
|
12
|
-
#
|
13
|
-
# @param [Hash] options
|
14
|
-
#
|
15
|
-
# Options:
|
16
|
-
# * :bucket - Bucket name (default juno)
|
17
|
-
# * :content_type - Default content type (default application/octet-stream)
|
18
|
-
# * All other options passed to Riak::Client#new
|
19
|
-
def initialize(options = {})
|
20
|
-
bucket = options.delete(:bucket) || 'juno'
|
21
|
-
@content_type = options.delete(:content_type) || 'application/octet-stream'
|
22
|
-
@bucket = ::Riak::Client.new(options).bucket(bucket)
|
23
|
-
end
|
24
|
-
|
25
|
-
def key?(key, options = {})
|
26
|
-
@bucket.exists?(key, options)
|
27
|
-
end
|
28
|
-
|
29
|
-
def load(key, options = {})
|
30
|
-
@bucket.get(key, options).raw_data
|
31
|
-
rescue ::Riak::FailedRequest => ex
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def delete(key, options = {})
|
36
|
-
value = load(key, options)
|
37
|
-
@bucket.delete(key, options)
|
38
|
-
value
|
39
|
-
end
|
40
|
-
|
41
|
-
def store(key, value, options = {})
|
42
|
-
obj = ::Riak::RObject.new(@bucket, key)
|
43
|
-
obj.content_type = options[:content_type] || @content_type
|
44
|
-
obj.raw_data = value
|
45
|
-
obj.store(options)
|
46
|
-
value
|
47
|
-
end
|
48
|
-
|
49
|
-
def clear(options = {})
|
50
|
-
@bucket.keys do |keys|
|
51
|
-
keys.each{ |key| @bucket.delete(key) }
|
52
|
-
end
|
53
|
-
self
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
data/lib/juno/adapters/sdbm.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'sdbm'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# SDBM backend
|
6
|
-
# @api public
|
7
|
-
class SDBM < Memory
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param [Hash] options
|
11
|
-
#
|
12
|
-
# Options:
|
13
|
-
# * :file - Database file
|
14
|
-
def initialize(options = {})
|
15
|
-
raise ArgumentError, 'Option :file is required' unless options[:file]
|
16
|
-
@memory = ::SDBM.new(options[:file])
|
17
|
-
end
|
18
|
-
|
19
|
-
def close
|
20
|
-
@memory.close
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def store(key, value, options = {})
|
25
|
-
super
|
26
|
-
value
|
27
|
-
rescue SDBMError
|
28
|
-
# SDBM is not very robust!
|
29
|
-
# You shouldn't put to much data into it, otherwise
|
30
|
-
# it might raise a SDBMError.
|
31
|
-
value
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/juno/adapters/sequel.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# Sequel backend
|
6
|
-
# @api public
|
7
|
-
class Sequel < Base
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param [Hash] options
|
11
|
-
#
|
12
|
-
# Options:
|
13
|
-
# * :db - Sequel database
|
14
|
-
# * :table - Table name (default :juno)
|
15
|
-
# * All other options passed to Sequel#connect
|
16
|
-
def initialize(options = {})
|
17
|
-
raise ArgumentError, 'Option :db is required' unless db = options.delete(:db)
|
18
|
-
@table = options.delete(:table) || :juno
|
19
|
-
@db = ::Sequel.connect(db, options)
|
20
|
-
@db.create_table?(@table) do
|
21
|
-
String :k, :null => false, :primary_key => true
|
22
|
-
String :v
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def key?(key, options = {})
|
27
|
-
sequel_table[:k => key] != nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def load(key, options = {})
|
31
|
-
result = sequel_table[:k => key]
|
32
|
-
result ? result[:v] : nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def store(key, value, options = {})
|
36
|
-
@db.transaction do
|
37
|
-
if key?(key, options)
|
38
|
-
sequel_table.update(:k => key, :v => value)
|
39
|
-
else
|
40
|
-
sequel_table.insert(:k => key, :v => value)
|
41
|
-
end
|
42
|
-
value
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def delete(key, options = {})
|
47
|
-
@db.transaction do
|
48
|
-
if value = load(key, options)
|
49
|
-
sequel_table.filter(:k => key).delete
|
50
|
-
value
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def clear(options = {})
|
56
|
-
sequel_table.delete
|
57
|
-
self
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def sequel_table
|
63
|
-
@sequel_table ||= @db[@table]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/lib/juno/adapters/sqlite.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'sqlite3'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# Sqlite3 backend
|
6
|
-
# @api public
|
7
|
-
class Sqlite < Base
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param [Hash] options
|
11
|
-
#
|
12
|
-
# Options:
|
13
|
-
# * :file - Database file
|
14
|
-
# * :table - Table name (default juno)
|
15
|
-
def initialize(options = {})
|
16
|
-
raise ArgumentError, 'Option :file is required' unless options[:file]
|
17
|
-
table = options[:table] || 'juno'
|
18
|
-
@db = ::SQLite3::Database.new(options[:file])
|
19
|
-
@db.execute("create table if not exists #{table} (k blob not null primary key, v blob)")
|
20
|
-
@select = @db.prepare("select v from #{table} where k = ?")
|
21
|
-
@insert = @db.prepare("insert or replace into #{table} values (?, ?)")
|
22
|
-
@delete = @db.prepare("delete from #{table} where k = ?")
|
23
|
-
@clear = @db.prepare("delete from #{table}")
|
24
|
-
end
|
25
|
-
|
26
|
-
def key?(key, options = {})
|
27
|
-
!@select.execute!(key).empty?
|
28
|
-
end
|
29
|
-
|
30
|
-
def load(key, options = {})
|
31
|
-
rows = @select.execute!(key)
|
32
|
-
rows.empty? ? nil : rows.first.first
|
33
|
-
end
|
34
|
-
|
35
|
-
def store(key, value, options = {})
|
36
|
-
@insert.execute!(key, value)
|
37
|
-
value
|
38
|
-
end
|
39
|
-
|
40
|
-
def delete(key, options = {})
|
41
|
-
value = load(key, options)
|
42
|
-
@delete.execute!(key)
|
43
|
-
value
|
44
|
-
end
|
45
|
-
|
46
|
-
def clear(options = {})
|
47
|
-
@clear.execute!
|
48
|
-
self
|
49
|
-
end
|
50
|
-
|
51
|
-
def close
|
52
|
-
@select.close
|
53
|
-
@insert.close
|
54
|
-
@delete.close
|
55
|
-
@clear.close
|
56
|
-
@db.close
|
57
|
-
nil
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'tokyocabinet'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# TokyoCabinet backend
|
6
|
-
# @api public
|
7
|
-
class TokyoCabinet < Memory
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param [Hash] options
|
11
|
-
#
|
12
|
-
# Options:
|
13
|
-
# * :file - Database file
|
14
|
-
# * :type - Database type (default :hdb, :bdb and :hdb possible)
|
15
|
-
def initialize(options = {})
|
16
|
-
file = options[:file]
|
17
|
-
raise ArgumentError, 'Option :file is required' unless options[:file]
|
18
|
-
if options[:type] == :bdb
|
19
|
-
@memory = ::TokyoCabinet::BDB.new
|
20
|
-
@memory.open(file, ::TokyoCabinet::BDB::OWRITER | ::TokyoCabinet::BDB::OCREAT)
|
21
|
-
else
|
22
|
-
@memory = ::TokyoCabinet::HDB.new
|
23
|
-
@memory.open(file, ::TokyoCabinet::HDB::OWRITER | ::TokyoCabinet::HDB::OCREAT)
|
24
|
-
end or raise @memory.errmsg(@memory.ecode)
|
25
|
-
end
|
26
|
-
|
27
|
-
def delete(key, options = {})
|
28
|
-
value = load(key, options)
|
29
|
-
if value
|
30
|
-
@memory.delete(key)
|
31
|
-
value
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def close
|
36
|
-
@memory.close
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/juno/adapters/yaml.rb
DELETED
data/lib/juno/base.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
module Juno
|
2
|
-
# Simple interface to key/value stores with Hash-like interface.
|
3
|
-
# @api public
|
4
|
-
class Base
|
5
|
-
# Exists the value with key
|
6
|
-
#
|
7
|
-
# @param [Object] key
|
8
|
-
# @return [Boolean]
|
9
|
-
# @param [Hash] options
|
10
|
-
# @api public
|
11
|
-
def key?(key, options = {})
|
12
|
-
load(key, options) != nil
|
13
|
-
end
|
14
|
-
|
15
|
-
# Explicitly close the store
|
16
|
-
# @api public
|
17
|
-
def close
|
18
|
-
end
|
19
|
-
|
20
|
-
# Fetch value with key
|
21
|
-
#
|
22
|
-
# This is a overloaded method:
|
23
|
-
#
|
24
|
-
# * fetch(key, options = {}, &block) retrieve a key. if the key is not available, execute the
|
25
|
-
# block and return its return value.
|
26
|
-
#
|
27
|
-
# * fetch(key, value, options = {}) retrieve a key. if the key is not available, return the value.
|
28
|
-
#
|
29
|
-
# @param [Object] key
|
30
|
-
# @param [Object] default Default value
|
31
|
-
# @param [Hash] options
|
32
|
-
# @return [Object] value from store
|
33
|
-
# @api public
|
34
|
-
def fetch(key, default = nil, options = nil)
|
35
|
-
if block_given?
|
36
|
-
raise ArgumentError, 'Only one argument accepted if block is given' if options
|
37
|
-
load(key, default || {}) || yield(key)
|
38
|
-
else
|
39
|
-
load(key, options || {}) || default
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Fetch value with key. Return nil if the key doesn't exist
|
44
|
-
#
|
45
|
-
# @param [Object] key
|
46
|
-
# @return [Object] value
|
47
|
-
# @api public
|
48
|
-
def [](key)
|
49
|
-
load(key)
|
50
|
-
end
|
51
|
-
|
52
|
-
# Store value with key
|
53
|
-
#
|
54
|
-
# @param [Object] key
|
55
|
-
# @param [Object] value
|
56
|
-
# @return value
|
57
|
-
# @api public
|
58
|
-
def []=(key, value)
|
59
|
-
store(key, value)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/lib/juno/builder.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Juno
|
2
|
-
# Builder implements the DSL to build a chain of store proxies
|
3
|
-
# @api private
|
4
|
-
class Builder
|
5
|
-
# @api private
|
6
|
-
def build
|
7
|
-
klass, options, block = @proxies.first
|
8
|
-
@proxies[1..-1].inject([klass.new(options, &block)]) do |stores, proxy|
|
9
|
-
klass, options, block = proxy
|
10
|
-
stores << klass.new(stores.last, options, &block)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(&block)
|
15
|
-
raise ArgumentError, 'No block given' unless block_given?
|
16
|
-
@proxies = []
|
17
|
-
instance_eval(&block)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Add proxy to chain
|
21
|
-
#
|
22
|
-
# @param [Symbol or Class] proxy Name of proxy class or proxy class
|
23
|
-
# @param [Hash] options Options hash
|
24
|
-
def use(proxy, options = {}, &block)
|
25
|
-
proxy = Juno.const_get(proxy) if Symbol === proxy
|
26
|
-
raise ArgumentError, 'You must give a Class or a Symbol' unless Class === proxy
|
27
|
-
@proxies.unshift [proxy, options, block]
|
28
|
-
nil
|
29
|
-
end
|
30
|
-
|
31
|
-
# Add adapter to chain
|
32
|
-
#
|
33
|
-
# @param [Symbol] name Name of adapter class
|
34
|
-
# @param [Hash] options Options hash
|
35
|
-
def adapter(name, options = {}, &block)
|
36
|
-
use(Adapters.const_get(name), options, &block)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/juno/cache.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
module Juno
|
2
|
-
# Combines two stores. One is used as cache, the other as backend.
|
3
|
-
#
|
4
|
-
# @example Add cache to chain
|
5
|
-
# Juno.build do
|
6
|
-
# use(:Cache) do
|
7
|
-
# backend { adapter :File, :dir => 'data' }
|
8
|
-
# cache { adapter :Memory }
|
9
|
-
# end
|
10
|
-
# end
|
11
|
-
#
|
12
|
-
# @api public
|
13
|
-
class Cache < Base
|
14
|
-
# @api private
|
15
|
-
class DSL
|
16
|
-
def initialize(options, &block)
|
17
|
-
@cache, @backend = options[:cache], options[:backend]
|
18
|
-
instance_eval(&block)
|
19
|
-
end
|
20
|
-
|
21
|
-
def backend(store = nil, &block)
|
22
|
-
raise 'Backend already set' if @backend
|
23
|
-
raise ArgumentError, 'Only argument or block allowed' if store && block
|
24
|
-
@backend = store || Juno.build(&block)
|
25
|
-
end
|
26
|
-
|
27
|
-
def cache(store = nil, &block)
|
28
|
-
raise 'Cache already set' if @cache
|
29
|
-
raise ArgumentError, 'Only argument or block allowed' if store && block
|
30
|
-
@cache = store || Juno.build(&block)
|
31
|
-
end
|
32
|
-
|
33
|
-
def result
|
34
|
-
[@cache, @backend]
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
attr_reader :cache, :backend
|
39
|
-
|
40
|
-
def initialize(options = {}, &block)
|
41
|
-
@cache, @backend = DSL.new(options, &block).result
|
42
|
-
end
|
43
|
-
|
44
|
-
def key?(key, options = {})
|
45
|
-
@cache.key?(key, options) || @backend.key?(key, options)
|
46
|
-
end
|
47
|
-
|
48
|
-
def load(key, options = {})
|
49
|
-
value = @cache.load(key, options)
|
50
|
-
unless value
|
51
|
-
value = @backend.load(key, options)
|
52
|
-
@cache.store(key, value, options) if value
|
53
|
-
end
|
54
|
-
value
|
55
|
-
end
|
56
|
-
|
57
|
-
def store(key, value, options = {})
|
58
|
-
@cache.store(key, value, options)
|
59
|
-
@backend.store(key, value, options)
|
60
|
-
end
|
61
|
-
|
62
|
-
def delete(key, options = {})
|
63
|
-
@cache.delete(key, options)
|
64
|
-
@backend.delete(key, options)
|
65
|
-
end
|
66
|
-
|
67
|
-
def clear(options = {})
|
68
|
-
@cache.clear(options)
|
69
|
-
@backend.clear(options)
|
70
|
-
self
|
71
|
-
end
|
72
|
-
|
73
|
-
def close
|
74
|
-
@cache.close
|
75
|
-
@backend.close
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|