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
@@ -1,89 +0,0 @@
|
|
1
|
-
# Copyright: 2011 TMX Credit
|
2
|
-
# Author: Potapov Sergey (aka Blake)
|
3
|
-
|
4
|
-
require 'cassandra'
|
5
|
-
|
6
|
-
module Juno
|
7
|
-
module Adapters
|
8
|
-
# Cassandra backend
|
9
|
-
# @api public
|
10
|
-
class Cassandra < Base
|
11
|
-
# Constructor
|
12
|
-
#
|
13
|
-
# @param [Hash] options
|
14
|
-
#
|
15
|
-
# Options:
|
16
|
-
# * :keyspace - Cassandra keyspace (default 'juno')
|
17
|
-
# * :column_family - Cassandra column family (default 'juno')
|
18
|
-
# * :host - Server host name (default 127.0.0.1)
|
19
|
-
# * :port - Server port (default 9160)
|
20
|
-
def initialize(options = {})
|
21
|
-
options[:host] ||= '127.0.0.1'
|
22
|
-
options[:port] ||= 9160
|
23
|
-
keyspace = (options[:keyspace] ||= 'juno')
|
24
|
-
@cf = (options[:column_family] || 'juno').to_sym
|
25
|
-
@client = ::Cassandra.new('system', "#{options[:host]}:#{options[:port]}")
|
26
|
-
unless @client.keyspaces.include?(keyspace)
|
27
|
-
cf_def = ::Cassandra::ColumnFamily.new(:keyspace => keyspace, :name => @cf.to_s)
|
28
|
-
ks_def = ::Cassandra::Keyspace.new(:name => keyspace,
|
29
|
-
:strategy_class => 'SimpleStrategy',
|
30
|
-
:strategy_options => { 'replication_factor' => '1' },
|
31
|
-
:replication_factor => 1,
|
32
|
-
:cf_defs => [cf_def])
|
33
|
-
# Wait for keyspace to be created (issue #24)
|
34
|
-
10.times do
|
35
|
-
begin
|
36
|
-
@client.add_keyspace(ks_def)
|
37
|
-
rescue Exception => ex
|
38
|
-
puts "Cassandra: #{ex.message}"
|
39
|
-
end
|
40
|
-
break if @client.keyspaces.include?(keyspace)
|
41
|
-
sleep 0.1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
@client.keyspace = keyspace
|
45
|
-
end
|
46
|
-
|
47
|
-
def key?(key, options = {})
|
48
|
-
if @client.exists?(@cf, key)
|
49
|
-
if options.include?(:expires) && (value = load(key))
|
50
|
-
store(key, value, options)
|
51
|
-
end
|
52
|
-
true
|
53
|
-
else
|
54
|
-
false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def load(key, options = {})
|
59
|
-
value = @client.get(@cf, key)
|
60
|
-
if value
|
61
|
-
if options.include?(:expires)
|
62
|
-
store(key, value['value'], options)
|
63
|
-
else
|
64
|
-
value['value']
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def delete(key, options = {})
|
70
|
-
if value = load(key, options)
|
71
|
-
@client.remove(@cf, key)
|
72
|
-
value
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def store(key, value, options = {})
|
77
|
-
@client.insert(@cf, key, {'value' => value}, :ttl => options[:expires])
|
78
|
-
value
|
79
|
-
end
|
80
|
-
|
81
|
-
def clear(options = {})
|
82
|
-
@client.each_key(@cf) do |key|
|
83
|
-
delete(key)
|
84
|
-
end
|
85
|
-
self
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
data/lib/juno/adapters/cookie.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Juno
|
2
|
-
module Adapters
|
3
|
-
class Cookie < Memory
|
4
|
-
attr_reader :cookies
|
5
|
-
|
6
|
-
def initialize(options = {})
|
7
|
-
super
|
8
|
-
@options, @cookies = options, {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def store(key, value, options = {})
|
12
|
-
cookie = @options.merge(options)
|
13
|
-
cookie[:value] = value
|
14
|
-
cookie[:expires] += Time.now.to_i if cookie[:expires]
|
15
|
-
@cookies[key] = cookie
|
16
|
-
super
|
17
|
-
end
|
18
|
-
|
19
|
-
def delete(key, options = {})
|
20
|
-
@cookies[key] = nil
|
21
|
-
super
|
22
|
-
end
|
23
|
-
|
24
|
-
def clear(options = {})
|
25
|
-
@memory.each_key { |key| @cookies[key] = nil }
|
26
|
-
super
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def reset(cookies)
|
31
|
-
@cookies, @memory = {}, cookies
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/juno/adapters/couch.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'couchrest'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# CouchDB backend
|
6
|
-
# @api public
|
7
|
-
class Couch < Base
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param [Hash] options
|
11
|
-
#
|
12
|
-
# Options:
|
13
|
-
# * :db - Couch database
|
14
|
-
def initialize(options = {})
|
15
|
-
raise ArgumentError, 'Option :db is required' unless options[:db]
|
16
|
-
@db = ::CouchRest.database!(options[:db])
|
17
|
-
end
|
18
|
-
|
19
|
-
def key?(key, options = {})
|
20
|
-
@db.get(key) != nil
|
21
|
-
rescue RestClient::ResourceNotFound
|
22
|
-
false
|
23
|
-
end
|
24
|
-
|
25
|
-
def load(key, options = {})
|
26
|
-
@db.get(key)['value']
|
27
|
-
rescue RestClient::ResourceNotFound
|
28
|
-
nil
|
29
|
-
end
|
30
|
-
|
31
|
-
def store(key, value, options = {})
|
32
|
-
doc = {'_id' => key, 'value' => value}
|
33
|
-
begin
|
34
|
-
doc['_rev'] = @db.get(key)['_rev']
|
35
|
-
rescue RestClient::ResourceNotFound
|
36
|
-
end
|
37
|
-
@db.save_doc(doc)
|
38
|
-
value
|
39
|
-
rescue RestClient::RequestFailed
|
40
|
-
value
|
41
|
-
end
|
42
|
-
|
43
|
-
def delete(key, options = {})
|
44
|
-
value = @db.get(key)
|
45
|
-
@db.delete_doc('_id' => value['_id'], '_rev' => value['_rev'])
|
46
|
-
value['value']
|
47
|
-
rescue RestClient::ResourceNotFound
|
48
|
-
nil
|
49
|
-
end
|
50
|
-
|
51
|
-
def clear(options = {})
|
52
|
-
@db.recreate!
|
53
|
-
self
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'dm-core'
|
2
|
-
require 'dm-migrations'
|
3
|
-
|
4
|
-
module Juno
|
5
|
-
module Adapters
|
6
|
-
# Datamapper backend
|
7
|
-
# @api public
|
8
|
-
class DataMapper < Base
|
9
|
-
class Store
|
10
|
-
include ::DataMapper::Resource
|
11
|
-
property :k, Text, :key => true
|
12
|
-
property :v, Text, :lazy => false
|
13
|
-
end
|
14
|
-
|
15
|
-
# Constructor
|
16
|
-
#
|
17
|
-
# @param [Hash] options
|
18
|
-
#
|
19
|
-
# Options:
|
20
|
-
# * :setup - Datamapper setup string
|
21
|
-
# * :repository - Repository name (default :juno)
|
22
|
-
# * :table - Table name (default :juno)
|
23
|
-
def initialize(options = {})
|
24
|
-
raise ArgumentError, 'Option :setup is required' unless options[:setup]
|
25
|
-
@repository = options.delete(:repository) || :juno
|
26
|
-
Store.storage_names[@repository] = (options.delete(:table) || :juno).to_s
|
27
|
-
::DataMapper.setup(@repository, options[:setup])
|
28
|
-
context { Store.auto_upgrade! }
|
29
|
-
end
|
30
|
-
|
31
|
-
def key?(key, options = {})
|
32
|
-
context { Store.get(key) != nil }
|
33
|
-
end
|
34
|
-
|
35
|
-
def load(key, options = {})
|
36
|
-
context do
|
37
|
-
record = Store.get(key)
|
38
|
-
record ? record.v : nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def store(key, value, options = {})
|
43
|
-
context do
|
44
|
-
record = Store.get(key)
|
45
|
-
if record
|
46
|
-
record.update(:k => key, :v => value)
|
47
|
-
else
|
48
|
-
Store.create(:k => key, :v => value)
|
49
|
-
end
|
50
|
-
value
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def delete(key, options = {})
|
55
|
-
context do
|
56
|
-
if record = Store.get(key)
|
57
|
-
value = record.v
|
58
|
-
record.destroy!
|
59
|
-
value
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def clear(options = {})
|
65
|
-
context { Store.all.destroy! }
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def context
|
72
|
-
::DataMapper.repository(@repository) { yield }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/lib/juno/adapters/dbm.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'dbm'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# DBM backend (Berkeley DB)
|
6
|
-
# @api public
|
7
|
-
class DBM < 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 = ::DBM.new(options[:file])
|
17
|
-
end
|
18
|
-
|
19
|
-
def close
|
20
|
-
@memory.close
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/juno/adapters/file.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# Filesystem backend
|
6
|
-
# @api public
|
7
|
-
class File < Base
|
8
|
-
def initialize(options = {})
|
9
|
-
raise ArgumentError, 'Option :dir is required' unless @dir = options[:dir]
|
10
|
-
FileUtils.mkpath(@dir)
|
11
|
-
raise "#{@dir} is not a directory" unless ::File.directory?(@dir)
|
12
|
-
end
|
13
|
-
|
14
|
-
def key?(key, options = {})
|
15
|
-
::File.exist?(store_path(key))
|
16
|
-
end
|
17
|
-
|
18
|
-
def load(key, options = {})
|
19
|
-
::File.read(store_path(key))
|
20
|
-
rescue Errno::ENOENT
|
21
|
-
end
|
22
|
-
|
23
|
-
def store(key, value, options = {})
|
24
|
-
path = store_path(key)
|
25
|
-
temp_file = ::File.join(@dir, "value-#{$$}-#{Thread.current.object_id}")
|
26
|
-
FileUtils.mkpath(::File.dirname(path))
|
27
|
-
::File.open(temp_file, 'wb') {|file| file.write(value) }
|
28
|
-
::File.unlink(path) if ::File.exist?(path)
|
29
|
-
::File.rename(temp_file, path)
|
30
|
-
value
|
31
|
-
rescue Errno::ENOENT
|
32
|
-
::File.unlink(temp_file) rescue nil
|
33
|
-
value
|
34
|
-
end
|
35
|
-
|
36
|
-
def delete(key, options = {})
|
37
|
-
value = load(key, options)
|
38
|
-
::File.unlink(store_path(key))
|
39
|
-
value
|
40
|
-
rescue Errno::ENOENT
|
41
|
-
end
|
42
|
-
|
43
|
-
def clear(options = {})
|
44
|
-
temp_dir = "#{@dir}-#{$$}-#{Thread.current.object_id}"
|
45
|
-
::File.rename(@dir, temp_dir)
|
46
|
-
FileUtils.mkpath(@dir)
|
47
|
-
FileUtils.rm_rf(temp_dir)
|
48
|
-
self
|
49
|
-
rescue Errno::ENOENT
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
|
-
protected
|
54
|
-
|
55
|
-
def store_path(key)
|
56
|
-
::File.join(@dir, key)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/juno/adapters/fog.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# Fog backend (Cloud storage services)
|
6
|
-
# @api public
|
7
|
-
class Fog < Base
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param [Hash] options
|
11
|
-
#
|
12
|
-
# Options:
|
13
|
-
# * :dir - Fog directory
|
14
|
-
# * Other options passed to Fog::Storage#new
|
15
|
-
def initialize(options = {})
|
16
|
-
raise ArgumentError, 'Option :dir is required' unless dir = options.delete(:dir)
|
17
|
-
storage = ::Fog::Storage.new(options)
|
18
|
-
@directory = storage.directories.create(:key => dir)
|
19
|
-
end
|
20
|
-
|
21
|
-
def key?(key, options = {})
|
22
|
-
@directory.files.head(key) != nil
|
23
|
-
end
|
24
|
-
|
25
|
-
def load(key, options = {})
|
26
|
-
value = @directory.files.get(key)
|
27
|
-
value ? value.body : nil
|
28
|
-
end
|
29
|
-
|
30
|
-
def delete(key, options = {})
|
31
|
-
if value = @directory.files.get(key)
|
32
|
-
body = value.body
|
33
|
-
value.destroy
|
34
|
-
body
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def store(key, value, options = {})
|
39
|
-
@directory.files.create(:key => key, :body => value)
|
40
|
-
value
|
41
|
-
end
|
42
|
-
|
43
|
-
def clear(options = {})
|
44
|
-
@directory.files.all.each do |file|
|
45
|
-
file.destroy
|
46
|
-
end
|
47
|
-
self
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/lib/juno/adapters/gdbm.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'gdbm'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# GDBM backend
|
6
|
-
# @api public
|
7
|
-
class GDBM < 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 = ::GDBM.new(options[:file])
|
17
|
-
end
|
18
|
-
|
19
|
-
def close
|
20
|
-
@memory.close
|
21
|
-
nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/juno/adapters/hbase.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'hbaserb'
|
2
|
-
|
3
|
-
module Juno
|
4
|
-
module Adapters
|
5
|
-
# HBase thrift backend
|
6
|
-
# @api public
|
7
|
-
class HBase < Base
|
8
|
-
# Constructor
|
9
|
-
#
|
10
|
-
# @param [Hash] options
|
11
|
-
#
|
12
|
-
# Options:
|
13
|
-
# * :host - Server host name (default 127.0.0.1)
|
14
|
-
# * :port - Server port (default 9090)
|
15
|
-
# * :table - Table name (default juno)
|
16
|
-
# * :column_family - Column family (default juno)
|
17
|
-
# * :column - Column (default value)
|
18
|
-
def initialize(options = {})
|
19
|
-
options[:host] ||= '127.0.0.1'
|
20
|
-
options[:port] ||= '9090'
|
21
|
-
options[:table] ||= 'juno'
|
22
|
-
options[:column] ||= 'value'
|
23
|
-
cf = (options[:column_family] || 'juno')
|
24
|
-
@db = HBaseRb::Client.new(options[:host], options[:port])
|
25
|
-
@db.create_table(options[:table], cf) unless @db.has_table?(options[:table])
|
26
|
-
@table = @db.get_table(options[:table])
|
27
|
-
@column = "#{cf}:#{options[:column]}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def key?(key, options = {})
|
31
|
-
@table.get(key, @column).first != nil
|
32
|
-
end
|
33
|
-
|
34
|
-
def load(key, options = {})
|
35
|
-
value = @table.get(key, @column).first
|
36
|
-
value ? value.value : nil
|
37
|
-
end
|
38
|
-
|
39
|
-
def delete(key, options = {})
|
40
|
-
if value = load(key, options)
|
41
|
-
@table.delete_row(key)
|
42
|
-
value
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def store(key, value, options = {})
|
47
|
-
@table.mutate_row(key, @column => value)
|
48
|
-
value
|
49
|
-
end
|
50
|
-
|
51
|
-
def clear(options = {})
|
52
|
-
@table.create_scanner do |row|
|
53
|
-
@table.delete_row(row.row)
|
54
|
-
end
|
55
|
-
self
|
56
|
-
end
|
57
|
-
|
58
|
-
def close
|
59
|
-
@db.close
|
60
|
-
nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|