benschwarz-smoke 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +47 -0
- data/VERSION.yml +2 -2
- data/lib/core_ext/string.rb +6 -0
- data/lib/smoke/cache.rb +38 -23
- data/lib/smoke/request.rb +4 -8
- data/lib/smoke.rb +7 -2
- data/rdoc/classes/Smoke/Origin.html +340 -0
- data/rdoc/classes/Smoke/Source/Data.html +126 -0
- data/rdoc/classes/Smoke/Source/Feed.html +117 -0
- data/rdoc/classes/Smoke/Source/YQL.html +223 -0
- data/rdoc/classes/Smoke.html +260 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README_markdown.html +180 -0
- data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
- data/rdoc/files/lib/smoke/origin_rb.html +49 -0
- data/rdoc/files/lib/smoke/request_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
- data/rdoc/files/lib/smoke_rb.html +65 -0
- data/rdoc/fr_class_index.html +21 -0
- data/rdoc/fr_file_index.html +28 -0
- data/rdoc/fr_method_index.html +4459 -0
- data/rdoc/index.html +15 -0
- data/rdoc/rdoc-style.css +319 -0
- data/spec/smoke/cache_spec.rb +28 -6
- data/vendor/crack/History +15 -0
- data/vendor/crack/LICENSE +20 -0
- data/vendor/crack/README.rdoc +42 -0
- data/vendor/crack/Rakefile +49 -0
- data/vendor/crack/VERSION.yml +4 -0
- data/vendor/crack/crack.gemspec +61 -0
- data/vendor/crack/lib/crack/core_extensions.rb +128 -0
- data/vendor/crack/lib/crack/json.rb +68 -0
- data/vendor/crack/lib/crack/xml.rb +214 -0
- data/vendor/crack/lib/crack.rb +7 -0
- data/vendor/crack/test/crack_test.rb +4 -0
- data/vendor/crack/test/data/twittersearch-firefox.json +1 -0
- data/vendor/crack/test/data/twittersearch-ie.json +1 -0
- data/vendor/crack/test/hash_test.rb +56 -0
- data/vendor/crack/test/json_test.rb +66 -0
- data/vendor/crack/test/string_test.rb +31 -0
- data/vendor/crack/test/test_helper.rb +12 -0
- data/vendor/crack/test/xml_test.rb +489 -0
- data/vendor/dependencies/README.markdown +113 -0
- data/vendor/dependencies/Rakefile +5 -0
- data/vendor/dependencies/bin/dep +83 -0
- data/vendor/dependencies/dependencies.gemspec +15 -0
- data/vendor/dependencies/dependencies.gemspec.erb +27 -0
- data/vendor/dependencies/lib/dependencies/dep.rb +99 -0
- data/vendor/dependencies/lib/dependencies.rb +5 -0
- data/vendor/dependencies/test/dependencies_test.rb +228 -0
- data/vendor/dependencies/test/foobaz-0.3.gem +0 -0
- data/vendor/fakeweb/CHANGELOG +163 -0
- data/vendor/fakeweb/LICENSE.txt +281 -0
- data/vendor/fakeweb/README.rdoc +193 -0
- data/vendor/fakeweb/Rakefile +76 -0
- data/vendor/fakeweb/fakeweb.gemspec +21 -0
- data/vendor/fakeweb/lib/fake_web/ext/net_http.rb +71 -0
- data/vendor/fakeweb/lib/fake_web/registry.rb +103 -0
- data/vendor/fakeweb/lib/fake_web/responder.rb +113 -0
- data/vendor/fakeweb/lib/fake_web/response.rb +10 -0
- data/vendor/fakeweb/lib/fake_web/stub_socket.rb +15 -0
- data/vendor/fakeweb/lib/fake_web/utility.rb +22 -0
- data/vendor/fakeweb/lib/fake_web.rb +172 -0
- data/vendor/fakeweb/lib/fakeweb.rb +2 -0
- data/vendor/fakeweb/test/fixtures/google_response_from_curl +12 -0
- data/vendor/fakeweb/test/fixtures/google_response_with_transfer_encoding +17 -0
- data/vendor/fakeweb/test/fixtures/google_response_without_transfer_encoding +11 -0
- data/vendor/fakeweb/test/fixtures/test_example.txt +1 -0
- data/vendor/fakeweb/test/fixtures/test_txt_file +3 -0
- data/vendor/fakeweb/test/test_allow_net_connect.rb +85 -0
- data/vendor/fakeweb/test/test_deprecations.rb +54 -0
- data/vendor/fakeweb/test/test_fake_authentication.rb +92 -0
- data/vendor/fakeweb/test/test_fake_web.rb +535 -0
- data/vendor/fakeweb/test/test_fake_web_open_uri.rb +58 -0
- data/vendor/fakeweb/test/test_helper.rb +74 -0
- data/vendor/fakeweb/test/test_missing_open_uri.rb +25 -0
- data/vendor/fakeweb/test/test_precedence.rb +51 -0
- data/vendor/fakeweb/test/test_query_string.rb +45 -0
- data/vendor/fakeweb/test/test_regexes.rb +103 -0
- data/vendor/fakeweb/test/test_response_headers.rb +73 -0
- data/vendor/fakeweb/test/test_trailing_slashes.rb +53 -0
- data/vendor/fakeweb/test/test_utility.rb +70 -0
- data/vendor/json-1.1.3/CHANGES +93 -0
- data/vendor/json-1.1.3/GPL +340 -0
- data/vendor/json-1.1.3/README +78 -0
- data/vendor/json-1.1.3/RUBY +58 -0
- data/vendor/json-1.1.3/Rakefile +309 -0
- data/vendor/json-1.1.3/TODO +1 -0
- data/vendor/json-1.1.3/VERSION +1 -0
- data/vendor/json-1.1.3/benchmarks/benchmark.txt +133 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_generator.rb +48 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_parser.rb +26 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_rails.rb +26 -0
- data/vendor/json-1.1.3/bin/edit_json.rb +10 -0
- data/vendor/json-1.1.3/bin/prettify_json.rb +76 -0
- data/vendor/json-1.1.3/data/example.json +1 -0
- data/vendor/json-1.1.3/data/index.html +38 -0
- data/vendor/json-1.1.3/data/prototype.js +4184 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/extconf.rb +9 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/generator.c +875 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/unicode.c +182 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/unicode.h +53 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/extconf.rb +9 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/parser.c +1758 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/parser.rl +638 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/unicode.c +154 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/unicode.h +58 -0
- data/vendor/json-1.1.3/install.rb +26 -0
- data/vendor/json-1.1.3/lib/json/Array.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/FalseClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Hash.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Key.xpm +73 -0
- data/vendor/json-1.1.3/lib/json/NilClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Numeric.xpm +28 -0
- data/vendor/json-1.1.3/lib/json/String.xpm +96 -0
- data/vendor/json-1.1.3/lib/json/TrueClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/add/core.rb +135 -0
- data/vendor/json-1.1.3/lib/json/add/rails.rb +58 -0
- data/vendor/json-1.1.3/lib/json/common.rb +354 -0
- data/vendor/json-1.1.3/lib/json/editor.rb +1362 -0
- data/vendor/json-1.1.3/lib/json/ext.rb +13 -0
- data/vendor/json-1.1.3/lib/json/json.xpm +1499 -0
- data/vendor/json-1.1.3/lib/json/pure/generator.rb +394 -0
- data/vendor/json-1.1.3/lib/json/pure/parser.rb +259 -0
- data/vendor/json-1.1.3/lib/json/pure.rb +75 -0
- data/vendor/json-1.1.3/lib/json/version.rb +9 -0
- data/vendor/json-1.1.3/lib/json.rb +235 -0
- data/vendor/json-1.1.3/tests/fixtures/fail1.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail10.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail11.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail12.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail13.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail14.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail18.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail19.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail2.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail20.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail21.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail22.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail23.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail24.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail25.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail27.json +2 -0
- data/vendor/json-1.1.3/tests/fixtures/fail28.json +2 -0
- data/vendor/json-1.1.3/tests/fixtures/fail3.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail4.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail5.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail6.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail7.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail8.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail9.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass1.json +56 -0
- data/vendor/json-1.1.3/tests/fixtures/pass15.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass16.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass17.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass2.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass26.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass3.json +6 -0
- data/vendor/json-1.1.3/tests/runner.rb +25 -0
- data/vendor/json-1.1.3/tests/test_json.rb +293 -0
- data/vendor/json-1.1.3/tests/test_json_addition.rb +161 -0
- data/vendor/json-1.1.3/tests/test_json_fixtures.rb +30 -0
- data/vendor/json-1.1.3/tests/test_json_generate.rb +100 -0
- data/vendor/json-1.1.3/tests/test_json_rails.rb +118 -0
- data/vendor/json-1.1.3/tests/test_json_unicode.rb +61 -0
- data/vendor/json-1.1.3/tools/fuzz.rb +140 -0
- data/vendor/json-1.1.3/tools/server.rb +62 -0
- data/vendor/moneta/LICENSE +20 -0
- data/vendor/moneta/README +51 -0
- data/vendor/moneta/Rakefile +60 -0
- data/vendor/moneta/TODO +4 -0
- data/vendor/moneta/benchmarks/various.rb +234 -0
- data/vendor/moneta/lib/moneta/basic_file.rb +111 -0
- data/vendor/moneta/lib/moneta/berkeley.rb +53 -0
- data/vendor/moneta/lib/moneta/couch.rb +63 -0
- data/vendor/moneta/lib/moneta/datamapper.rb +117 -0
- data/vendor/moneta/lib/moneta/file.rb +91 -0
- data/vendor/moneta/lib/moneta/lmc.rb +52 -0
- data/vendor/moneta/lib/moneta/memcache.rb +53 -0
- data/vendor/moneta/lib/moneta/memory.rb +11 -0
- data/vendor/moneta/lib/moneta/mongodb.rb +58 -0
- data/vendor/moneta/lib/moneta/redis.rb +49 -0
- data/vendor/moneta/lib/moneta/rufus.rb +41 -0
- data/vendor/moneta/lib/moneta/s3.rb +162 -0
- data/vendor/moneta/lib/moneta/sdbm.rb +33 -0
- data/vendor/moneta/lib/moneta/tyrant.rb +58 -0
- data/vendor/moneta/lib/moneta/xattr.rb +58 -0
- data/vendor/moneta/lib/moneta.rb +76 -0
- data/vendor/moneta/moneta.gemspec +32 -0
- data/vendor/moneta/script/destroy +14 -0
- data/vendor/moneta/script/generate +14 -0
- data/vendor/moneta/spec/moneta_basic_file_spec.rb +50 -0
- data/vendor/moneta/spec/moneta_berkeley_spec.rb +20 -0
- data/vendor/moneta/spec/moneta_couch_spec.rb +22 -0
- data/vendor/moneta/spec/moneta_datamapper_spec.rb +79 -0
- data/vendor/moneta/spec/moneta_file_spec.rb +21 -0
- data/vendor/moneta/spec/moneta_lmc_spec.rb +24 -0
- data/vendor/moneta/spec/moneta_memcache_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_memory_spec.rb +12 -0
- data/vendor/moneta/spec/moneta_mongodb_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_redis_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_rufus_spec.rb +15 -0
- data/vendor/moneta/spec/moneta_s3_spec.rb +19 -0
- data/vendor/moneta/spec/moneta_sdbm_spec.rb +21 -0
- data/vendor/moneta/spec/moneta_tyrant_spec.rb +15 -0
- data/vendor/moneta/spec/moneta_xattr_spec.rb +21 -0
- data/vendor/moneta/spec/shared.rb +122 -0
- data/vendor/moneta/spec/spec_helper.rb +7 -0
- data/vendor/rest-client/README.rdoc +151 -0
- data/vendor/rest-client/Rakefile +58 -0
- data/vendor/rest-client/VERSION +1 -0
- data/vendor/rest-client/bin/restclient +87 -0
- data/vendor/rest-client/lib/rest_client.rb +2 -0
- data/vendor/rest-client/lib/restclient/exceptions.rb +88 -0
- data/vendor/rest-client/lib/restclient/mixin/response.rb +43 -0
- data/vendor/rest-client/lib/restclient/raw_response.rb +30 -0
- data/vendor/rest-client/lib/restclient/request.rb +238 -0
- data/vendor/rest-client/lib/restclient/resource.rb +146 -0
- data/vendor/rest-client/lib/restclient/response.rb +20 -0
- data/vendor/rest-client/lib/restclient.rb +99 -0
- data/vendor/rest-client/rest-client.gemspec +66 -0
- data/vendor/rest-client/spec/base.rb +4 -0
- data/vendor/rest-client/spec/exceptions_spec.rb +65 -0
- data/vendor/rest-client/spec/mixin/response_spec.rb +46 -0
- data/vendor/rest-client/spec/raw_response_spec.rb +17 -0
- data/vendor/rest-client/spec/request_spec.rb +476 -0
- data/vendor/rest-client/spec/resource_spec.rb +75 -0
- data/vendor/rest-client/spec/response_spec.rb +16 -0
- data/vendor/rest-client/spec/restclient_spec.rb +53 -0
- data/vendor/simple-rss/LICENSE +429 -0
- data/vendor/simple-rss/README +43 -0
- data/vendor/simple-rss/Rakefile +212 -0
- data/vendor/simple-rss/install.rb +40 -0
- data/vendor/simple-rss/lib/simple-rss.rb +150 -0
- data/vendor/simple-rss/simple-rss.gemspec +12 -0
- data/vendor/simple-rss/test/base/base_test.rb +51 -0
- data/vendor/simple-rss/test/data/atom.xml +45 -0
- data/vendor/simple-rss/test/data/not-rss.xml +8 -0
- data/vendor/simple-rss/test/data/rss09.rdf +79 -0
- data/vendor/simple-rss/test/data/rss20.xml +818 -0
- data/vendor/simple-rss/test/test_helper.rb +4 -0
- metadata +314 -40
@@ -0,0 +1,162 @@
|
|
1
|
+
begin
|
2
|
+
require "right_aws"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the RightScale AWS gem to use the S3 moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
# An S3 implementation of Moneta
|
10
|
+
#
|
11
|
+
# Example usage:
|
12
|
+
#
|
13
|
+
# require 'rubygems'
|
14
|
+
# require 'moneta'
|
15
|
+
# require 'moneta/s3'
|
16
|
+
#
|
17
|
+
# store = Moneta::S3.new(
|
18
|
+
# :access_key_id => 'ACCESS_KEY_ID',
|
19
|
+
# :secret_access_key => 'SECRET_ACCESS_KEY',
|
20
|
+
# :bucket => 'a_bucket'
|
21
|
+
# )
|
22
|
+
# store['somefile']
|
23
|
+
class S3
|
24
|
+
# Initialize the Moneta::S3 store.
|
25
|
+
#
|
26
|
+
# Required values passed in the options hash:
|
27
|
+
# * <tt>:access_key_id</tt>: The access id key
|
28
|
+
# * <tt>:secret_access_key</tt>: The secret key
|
29
|
+
# * <tt>:bucket</tt>: The name of bucket. Will be created if it doesn't
|
30
|
+
# exist.
|
31
|
+
# * <tt>:multi_thread</tt>: Set to true if using threading
|
32
|
+
def initialize(options = {})
|
33
|
+
validate_options(options)
|
34
|
+
s3 = RightAws::S3.new(
|
35
|
+
options[:access_key_id],
|
36
|
+
options[:secret_access_key],
|
37
|
+
{
|
38
|
+
:logger => logger,
|
39
|
+
:multi_thread => options.delete(:multi_thread) || false
|
40
|
+
}
|
41
|
+
)
|
42
|
+
@bucket = s3.bucket(options.delete(:bucket), true)
|
43
|
+
end
|
44
|
+
|
45
|
+
def key?(key)
|
46
|
+
!s3_key(key).nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
alias has_key? key?
|
50
|
+
|
51
|
+
def [](key)
|
52
|
+
get(key)
|
53
|
+
end
|
54
|
+
|
55
|
+
def []=(key, value)
|
56
|
+
store(key, value)
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(key)
|
60
|
+
k = s3_key(key)
|
61
|
+
if k
|
62
|
+
value = k.get
|
63
|
+
k.delete
|
64
|
+
value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Store the key/value pair.
|
69
|
+
#
|
70
|
+
# Options:
|
71
|
+
# *<tt>:meta_headers</tt>: Meta headers passed to S3
|
72
|
+
# *<tt>:perms</tt>: Permissions passed to S3
|
73
|
+
# *<tt>:headers</tt>: Headers sent as part of the PUT request
|
74
|
+
# *<tt>:expires_in</tt>: Number of seconds until expiration
|
75
|
+
def store(key, value, options = {})
|
76
|
+
debug "store(key=#{key}, value=#{value}, options=#{options.inspect})"
|
77
|
+
meta_headers = meta_headers_from_options(options)
|
78
|
+
perms = options[:perms]
|
79
|
+
headers = options[:headers] || {}
|
80
|
+
|
81
|
+
case value
|
82
|
+
when IO
|
83
|
+
@bucket.put(key, value.read, meta_headers, perms, headers)
|
84
|
+
else
|
85
|
+
@bucket.put(key, value, meta_headers, perms, headers)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def update_key(key, options = {})
|
90
|
+
debug "update_key(key=#{key}, options=#{options.inspect})"
|
91
|
+
k = s3_key(key, false)
|
92
|
+
k.save_meta(meta_headers_from_options(options)) unless k.nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
def clear
|
96
|
+
@bucket.clear
|
97
|
+
end
|
98
|
+
|
99
|
+
protected
|
100
|
+
def logger
|
101
|
+
@logger ||= begin
|
102
|
+
logger = Logger.new(STDOUT)
|
103
|
+
logger.level = Logger::FATAL
|
104
|
+
logger
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
def validate_options(options)
|
110
|
+
unless options[:access_key_id]
|
111
|
+
raise RuntimeError, ":access_key_id is required in options"
|
112
|
+
end
|
113
|
+
unless options[:secret_access_key]
|
114
|
+
raise RuntimeError, ":secret_access_key is required in options"
|
115
|
+
end
|
116
|
+
unless options[:bucket]
|
117
|
+
raise RuntimeError, ":bucket is required in options"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def get(key)
|
122
|
+
k = s3_key(key)
|
123
|
+
k.nil? ? nil : k.get
|
124
|
+
end
|
125
|
+
|
126
|
+
def s3_key(key, nil_if_expired=true)
|
127
|
+
begin
|
128
|
+
s3_key = @bucket.key(key, true)
|
129
|
+
if s3_key.exists?
|
130
|
+
logger.debug "[Moneta::S3] key exists: #{key}"
|
131
|
+
if s3_key.meta_headers.has_key?('expires-at')
|
132
|
+
expires_at = Time.parse(s3_key.meta_headers['expires-at'])
|
133
|
+
if Time.now > expires_at && nil_if_expired
|
134
|
+
# TODO delete the object?
|
135
|
+
debug "key expired: #{key} (@#{s3_key.meta_headers['expires-at']})"
|
136
|
+
return nil
|
137
|
+
end
|
138
|
+
end
|
139
|
+
return s3_key
|
140
|
+
else
|
141
|
+
debug "key does not exist: #{key}"
|
142
|
+
end
|
143
|
+
rescue RightAws::AwsError => e
|
144
|
+
debug "key does not exist: #{key}"
|
145
|
+
end
|
146
|
+
nil
|
147
|
+
end
|
148
|
+
|
149
|
+
def meta_headers_from_options(options={})
|
150
|
+
meta_headers = options[:meta_headers] || {}
|
151
|
+
if options[:expires_in]
|
152
|
+
meta_headers['expires-at'] = (Time.now + options[:expires_in]).rfc2822
|
153
|
+
end
|
154
|
+
debug "setting expires-at: #{meta_headers['expires-at']}"
|
155
|
+
meta_headers
|
156
|
+
end
|
157
|
+
|
158
|
+
def debug(message)
|
159
|
+
logger.debug "[Moneta::S3] #{message}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "sdbm"
|
2
|
+
|
3
|
+
module Moneta
|
4
|
+
class BasicSDBM < ::SDBM
|
5
|
+
include Defaults
|
6
|
+
|
7
|
+
def [](key)
|
8
|
+
if val = super
|
9
|
+
Marshal.load(val)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def []=(key, value)
|
14
|
+
super(key, Marshal.dump(value))
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(key)
|
18
|
+
if val = super
|
19
|
+
Marshal.load(val)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class SDBM < BasicSDBM
|
25
|
+
include Expires
|
26
|
+
|
27
|
+
def initialize(options = {})
|
28
|
+
raise "No :file option specified" unless file = options[:file]
|
29
|
+
@expiration = BasicSDBM.new("#{file}_expires")
|
30
|
+
super(file)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
begin
|
2
|
+
require "rufus/tokyo/tyrant"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the rufus gem to use the Tyrant moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
class Tyrant < ::Rufus::Tokyo::Tyrant
|
10
|
+
include Defaults
|
11
|
+
|
12
|
+
module Implementation
|
13
|
+
def initialize(options = {})
|
14
|
+
host = options[:host]
|
15
|
+
port = options[:port]
|
16
|
+
super(host, port)
|
17
|
+
end
|
18
|
+
|
19
|
+
def key?(key)
|
20
|
+
!!self[key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](key)
|
24
|
+
if val = super
|
25
|
+
Marshal.load(val.unpack("m")[0])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def []=(key, value)
|
30
|
+
super(key, [Marshal.dump(value)].pack("m"))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
include Implementation
|
35
|
+
include Expires
|
36
|
+
|
37
|
+
def initialize(options = {})
|
38
|
+
super
|
39
|
+
@expiration = Expiration.new(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
class Expiration < ::Rufus::Tokyo::Tyrant
|
43
|
+
include Implementation
|
44
|
+
|
45
|
+
def [](key)
|
46
|
+
super("#{key}__expiration")
|
47
|
+
end
|
48
|
+
|
49
|
+
def []=(key, value)
|
50
|
+
super("#{key}__expiration", value)
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete(key)
|
54
|
+
super("#{key}__expiration")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
begin
|
2
|
+
require "xattr"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the xattr gem to use the Xattr moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
require "fileutils"
|
8
|
+
|
9
|
+
module Moneta
|
10
|
+
class Xattr
|
11
|
+
include Defaults
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
file = options[:file]
|
15
|
+
@hash = ::Xattr.new(file)
|
16
|
+
FileUtils.mkdir_p(::File.dirname(file))
|
17
|
+
FileUtils.touch(file)
|
18
|
+
unless options[:skip_expires]
|
19
|
+
@expiration = Moneta::Xattr.new(:file => "#{file}_expiration", :skip_expires => true)
|
20
|
+
self.extend(Expires)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Implementation
|
25
|
+
|
26
|
+
def key?(key)
|
27
|
+
@hash.list.include?(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
alias has_key? key?
|
31
|
+
|
32
|
+
def [](key)
|
33
|
+
return nil unless key?(key)
|
34
|
+
Marshal.load(@hash.get(key))
|
35
|
+
end
|
36
|
+
|
37
|
+
def []=(key, value)
|
38
|
+
@hash.set(key, Marshal.dump(value))
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(key)
|
42
|
+
return nil unless key?(key)
|
43
|
+
value = self[key]
|
44
|
+
@hash.remove(key)
|
45
|
+
value
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear
|
49
|
+
@hash.list.each do |item|
|
50
|
+
@hash.remove(item)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
include Implementation
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Moneta
|
2
|
+
module Expires
|
3
|
+
def check_expired(key)
|
4
|
+
if @expiration[key] && Time.now > @expiration[key]
|
5
|
+
@expiration.delete(key)
|
6
|
+
self.delete(key)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def key?(key)
|
11
|
+
check_expired(key)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def [](key)
|
16
|
+
check_expired(key)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def fetch(key, default = nil, &blk)
|
21
|
+
check_expired(key)
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(key)
|
26
|
+
check_expired(key)
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_key(key, options)
|
31
|
+
update_options(key, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def store(key, value, options = {})
|
35
|
+
ret = super(key, value)
|
36
|
+
update_options(key, options)
|
37
|
+
ret
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def update_options(key, options)
|
42
|
+
if options[:expires_in]
|
43
|
+
@expiration[key] = (Time.now + options[:expires_in])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module StringExpires
|
49
|
+
include Expires
|
50
|
+
|
51
|
+
def check_expired(key)
|
52
|
+
if @expiration[key] && Time.now > Time.at(@expiration[key].to_i)
|
53
|
+
@expiration.delete(key)
|
54
|
+
delete(key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def update_options(key, options)
|
60
|
+
if options[:expires_in]
|
61
|
+
@expiration[key] = (Time.now + options[:expires_in]).to_i.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Defaults
|
67
|
+
def fetch(key, value = nil)
|
68
|
+
value ||= block_given? ? yield(key) : default
|
69
|
+
self[key] || value
|
70
|
+
end
|
71
|
+
|
72
|
+
def store(key, value, options = {})
|
73
|
+
self[key] = value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# June 1, 1:00pm
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = %q{moneta}
|
7
|
+
s.version = "0.6.0"
|
8
|
+
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.authors = ["Yehuda Katz"]
|
11
|
+
s.autorequire = %q{moneta}
|
12
|
+
s.date = %q{2009-02-12}
|
13
|
+
s.description = %q{A unified interface to key/value stores}
|
14
|
+
s.email = %q{wycats@gmail.com}
|
15
|
+
s.extra_rdoc_files = ["README", "LICENSE", "TODO"]
|
16
|
+
s.files = ["LICENSE", "README", "Rakefile", "TODO", "lib/moneta", "lib/moneta/datamapper.rb", "lib/moneta/file.rb", "lib/moneta/memcache.rb", "lib/moneta/memory.rb", "lib/moneta/xattr.rb", "lib/moneta.rb"]
|
17
|
+
s.has_rdoc = true
|
18
|
+
s.homepage = %q{http://www.yehudakatz.com}
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubygems_version = %q{1.3.1}
|
21
|
+
s.summary = %q{A unified interface to key/value stores}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:newgem_simple, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:newgem_simple, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "moneta/basic_file"
|
5
|
+
|
6
|
+
describe "Moneta::BasicFile" do
|
7
|
+
describe "without namespacing" do
|
8
|
+
before(:each) do
|
9
|
+
@cache = Moneta::BasicFile.new(:path => File.join(File.dirname(__FILE__), "basic_file_cache"))
|
10
|
+
@cache.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
if ENV['MONETA_TEST'].nil? || ENV['MONETA_TEST'] == 'basic_file'
|
14
|
+
it_should_behave_like "a read/write Moneta cache"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should deal with '/' and '#' in a key" do
|
18
|
+
key = "hello/mom#crazycharacters"
|
19
|
+
@cache[key] = "hi"
|
20
|
+
@cache[key].should == "hi"
|
21
|
+
::File.exists?(File.join(File.dirname(__FILE__), "basic_file_cache", "")).should == true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "with namespacing" do
|
26
|
+
before(:each) do
|
27
|
+
@cache = Moneta::BasicFile.new(:path => File.join(File.dirname(__FILE__), "basic_file_cache"), :namespace => "test_namespace")
|
28
|
+
@cache.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
if ENV['MONETA_TEST'].nil? || ENV['MONETA_TEST'] == 'basic_file'
|
32
|
+
it_should_behave_like "a read/write Moneta cache"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should act as two stores within the same directory" do
|
36
|
+
@second = Moneta::BasicFile.new(:path => File.join(File.dirname(__FILE__), "basic_file_cache"), :namespace => "second_namespace")
|
37
|
+
@second[:key] = "hello"
|
38
|
+
@cache[:key] = "world!"
|
39
|
+
@second[:key].should == "hello"
|
40
|
+
@cache[:key].should == "world!"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
after(:all) do
|
45
|
+
FileUtils.rm_rf(File.join(File.dirname(__FILE__), "basic_file_cache"))
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
rescue SystemExit
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'moneta/berkeley'
|
5
|
+
|
6
|
+
describe "Moneta::Berkeley" do
|
7
|
+
before(:each) do
|
8
|
+
@cache = Moneta::Berkeley.new(:file => File.join(File.dirname(__FILE__), "berkeley_test.db"))
|
9
|
+
@cache.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
File.delete(File.join(File.dirname(__FILE__), "berkeley_test.db"))
|
14
|
+
File.delete(File.join(File.dirname(__FILE__), "berkeley_test.db_expiration"))
|
15
|
+
end
|
16
|
+
|
17
|
+
it_should_behave_like "a read/write Moneta cache"
|
18
|
+
end
|
19
|
+
rescue SystemExit
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'moneta/couch'
|
5
|
+
|
6
|
+
describe "Moneta::Couch" do
|
7
|
+
before(:each) do
|
8
|
+
@cache = Moneta::Couch.new(:db => "couch_test")
|
9
|
+
@expiration = Moneta::Couch.new(:db => "couch_test_expiration", :skip_expires => true)
|
10
|
+
@cache.clear
|
11
|
+
@expiration.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
@cache.delete_store
|
16
|
+
@expiration.delete_store
|
17
|
+
end
|
18
|
+
|
19
|
+
it_should_behave_like "a read/write Moneta cache"
|
20
|
+
end
|
21
|
+
rescue SystemExit
|
22
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "moneta/datamapper"
|
5
|
+
|
6
|
+
describe "Moneta::DataMapper" do
|
7
|
+
|
8
|
+
describe "default repository" do
|
9
|
+
before(:each) do
|
10
|
+
@cache = Moneta::DataMapper.new(:setup => "sqlite3::memory:")
|
11
|
+
@cache.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
repository(:moneta) { MonetaHash.auto_migrate! }
|
16
|
+
end
|
17
|
+
|
18
|
+
it_should_behave_like "a read/write Moneta cache"
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when :repository specified" do
|
22
|
+
before(:each) do
|
23
|
+
@cache = Moneta::DataMapper.new(:repository => :sample, :setup => "sqlite3::memory:")
|
24
|
+
@cache.clear
|
25
|
+
end
|
26
|
+
|
27
|
+
after(:all) do
|
28
|
+
repository(:sample) { MonetaHash.auto_migrate! }
|
29
|
+
end
|
30
|
+
|
31
|
+
it_should_behave_like "a read/write Moneta cache"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with multple stores" do
|
35
|
+
before(:each) do
|
36
|
+
@default_cache = Moneta::DataMapper.new(:setup => "sqlite3:moneta.db")
|
37
|
+
@default_cache.clear
|
38
|
+
|
39
|
+
@sample_cache = Moneta::DataMapper.new(:repository => :sample, :setup => "sqlite3:sample.db")
|
40
|
+
@sample_cache.clear
|
41
|
+
end
|
42
|
+
|
43
|
+
after(:all) do
|
44
|
+
File.delete('moneta.db')
|
45
|
+
File.delete('sample.db')
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO should there be more tests than these?
|
49
|
+
it "does not cross contaminate when storing" do
|
50
|
+
@default_cache["key"] = "value"
|
51
|
+
@sample_cache["key"] = "value2"
|
52
|
+
|
53
|
+
@default_cache["key"].should == "value"
|
54
|
+
@sample_cache["key"].should == "value2"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "does not cross contaminate when deleting" do
|
58
|
+
@default_cache["key"] = "value"
|
59
|
+
@sample_cache["key"] = "value2"
|
60
|
+
|
61
|
+
@default_cache.delete("key").should == "value"
|
62
|
+
@default_cache.key?("key").should be_false
|
63
|
+
@sample_cache["key"].should == "value2"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "does not cross contaminate when expiring" do
|
67
|
+
@default_cache.store("key", "value", :expires_in => 2)
|
68
|
+
@sample_cache["key"] = "value2"
|
69
|
+
|
70
|
+
time = Time.now
|
71
|
+
Time.stub!(:now).and_return { time + 2 }
|
72
|
+
|
73
|
+
@default_cache["key"].should == nil
|
74
|
+
@sample_cache["key"].should == "value2"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
rescue SystemExit
|
79
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "moneta/file"
|
5
|
+
|
6
|
+
describe "Moneta::File" do
|
7
|
+
before(:each) do
|
8
|
+
@cache = Moneta::File.new(:path => File.join(File.dirname(__FILE__), "file_cache"))
|
9
|
+
@cache.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
FileUtils.rm_rf(File.join(File.dirname(__FILE__), "file_cache"))
|
14
|
+
end
|
15
|
+
|
16
|
+
if ENV['MONETA_TEST'].nil? || ENV['MONETA_TEST'] == 'file'
|
17
|
+
it_should_behave_like "a read/write Moneta cache"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
rescue SystemExit
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "moneta/lmc"
|
5
|
+
require "fileutils"
|
6
|
+
|
7
|
+
# Problem: If there are multiple caches around, they start
|
8
|
+
# to block (with a system semaphore), which can be unpleasant
|
9
|
+
# so just use one cache for the entire test run.
|
10
|
+
$lmc_cache = Moneta::LMC.new(:filename => "test")
|
11
|
+
|
12
|
+
describe "Moneta::LMC" do
|
13
|
+
before(:all) do
|
14
|
+
@cache = $lmc_cache
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
@cache.clear
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "a read/write Moneta cache"
|
22
|
+
end
|
23
|
+
rescue SystemExit
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "moneta/memcache"
|
5
|
+
|
6
|
+
describe "Moneta::Memcache" do
|
7
|
+
before(:each) do
|
8
|
+
@native_expires = true
|
9
|
+
@cache = Moneta::Memcache.new(:server => "localhost:11211", :namespace => "moneta_spec")
|
10
|
+
@cache.clear
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "a read/write Moneta cache"
|
14
|
+
end
|
15
|
+
rescue SystemExit
|
16
|
+
end
|