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,111 @@
|
|
1
|
+
#
|
2
|
+
# Basic File Store
|
3
|
+
# by Hampton Catlin
|
4
|
+
#
|
5
|
+
# This cache simply uses a directory that it creates
|
6
|
+
# and manages to keep your file stores.
|
7
|
+
#
|
8
|
+
# Specify :skip_expires => true if you aren't using
|
9
|
+
# expiration as this will slightly decrease your file size
|
10
|
+
# and memory footprint of the library
|
11
|
+
#
|
12
|
+
# You can optionally also specify a :namespace
|
13
|
+
# option that will create a subfolder.
|
14
|
+
#
|
15
|
+
|
16
|
+
|
17
|
+
require 'fileutils'
|
18
|
+
require File.join(File.dirname(__FILE__), "..", "moneta.rb")
|
19
|
+
|
20
|
+
module Moneta
|
21
|
+
class BasicFile
|
22
|
+
include Defaults
|
23
|
+
|
24
|
+
def initialize(options = {})
|
25
|
+
@namespace = options[:namespace]
|
26
|
+
@directory = ::File.join(options[:path], @namespace.to_s)
|
27
|
+
|
28
|
+
@expires = !options[:skip_expires]
|
29
|
+
|
30
|
+
ensure_directory_created(@directory)
|
31
|
+
end
|
32
|
+
|
33
|
+
def key?(key)
|
34
|
+
!self[key].nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
alias has_key? key?
|
38
|
+
|
39
|
+
def [](key)
|
40
|
+
if ::File.exist?(path(key))
|
41
|
+
data = raw_get(key)
|
42
|
+
if @expires
|
43
|
+
if data[:expires_at].nil? || data[:expires_at] > Time.now
|
44
|
+
data[:value]
|
45
|
+
else
|
46
|
+
delete!(key)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def raw_get(key)
|
53
|
+
Marshal.load(::File.read(path(key)))
|
54
|
+
end
|
55
|
+
|
56
|
+
def []=(key, value)
|
57
|
+
store(key, value)
|
58
|
+
end
|
59
|
+
|
60
|
+
def store(key, value, options = {})
|
61
|
+
ensure_directory_created(::File.dirname(path(key)))
|
62
|
+
::File.open(path(key), "w") do |file|
|
63
|
+
if @expires
|
64
|
+
data = {:value => value}
|
65
|
+
if options[:expires_in]
|
66
|
+
data[:expires_at] = Time.now + options[:expires_in]
|
67
|
+
end
|
68
|
+
contents = Marshal.dump(data)
|
69
|
+
else
|
70
|
+
contents = Marshal.dump(value)
|
71
|
+
end
|
72
|
+
file.puts(contents)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def update_key(key, options)
|
77
|
+
store(key, self[key], options)
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete!(key)
|
81
|
+
FileUtils.rm(path(key))
|
82
|
+
nil
|
83
|
+
rescue Errno::ENOENT
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete(key)
|
87
|
+
value = self[key]
|
88
|
+
delete!(key)
|
89
|
+
value
|
90
|
+
end
|
91
|
+
|
92
|
+
def clear
|
93
|
+
FileUtils.rm_rf(@directory)
|
94
|
+
FileUtils.mkdir(@directory)
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
def path(key)
|
99
|
+
::File.join(@directory, key.to_s)
|
100
|
+
end
|
101
|
+
|
102
|
+
def ensure_directory_created(directory_path)
|
103
|
+
if ::File.file?(directory_path)
|
104
|
+
raise StandardError, "The path you supplied #{directory_path} is a file"
|
105
|
+
elsif !::File.exists?(directory_path)
|
106
|
+
FileUtils.mkdir_p(directory_path)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
begin
|
2
|
+
require 'bdb'
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need bdb gem to use Bdb moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
|
10
|
+
class Berkeley
|
11
|
+
include Defaults
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
file = @file = options[:file]
|
15
|
+
@db = Bdb::Db.new()
|
16
|
+
@db.open(nil, file, nil, Bdb::Db::BTREE, Bdb::DB_CREATE, 0)
|
17
|
+
unless options[:skip_expires]
|
18
|
+
@expiration = Moneta::Berkeley.new(:file => "#{file}_expiration", :skip_expires => true )
|
19
|
+
self.extend(StringExpires)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Implementation
|
24
|
+
def key?(key)
|
25
|
+
nil | self[key]
|
26
|
+
end
|
27
|
+
|
28
|
+
alias has_key? key?
|
29
|
+
|
30
|
+
def []=(key,value)
|
31
|
+
@db[key] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](key)
|
35
|
+
@db[key]
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete(key)
|
39
|
+
value = self[key]
|
40
|
+
@db.del(nil,key,0) if value
|
41
|
+
value
|
42
|
+
end
|
43
|
+
|
44
|
+
def clear
|
45
|
+
@db.truncate(nil)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
include Implementation
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
begin
|
2
|
+
require "couchrest"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the couchrest gem to use the CouchDB store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
class Couch
|
10
|
+
include Defaults
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@db = ::CouchRest.database!(options[:db])
|
14
|
+
unless options[:skip_expires]
|
15
|
+
@expiration = Moneta::Couch.new(:db => "#{options[:db]}_expiration", :skip_expires => true)
|
16
|
+
self.extend(StringExpires)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def key?(key)
|
21
|
+
!self[key].nil?
|
22
|
+
rescue RestClient::ResourceNotFound
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
alias has_key? key?
|
27
|
+
|
28
|
+
def [](key)
|
29
|
+
@db.get(key)["data"]
|
30
|
+
rescue RestClient::ResourceNotFound
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def []=(key, value)
|
35
|
+
@db.save_doc("_id" => key, :data => value)
|
36
|
+
rescue RestClient::RequestFailed
|
37
|
+
self[key]
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(key)
|
41
|
+
value = @db.get(key)
|
42
|
+
@db.delete_doc({"_id" => value["_id"], "_rev" => value["_rev"]}) if value
|
43
|
+
value["data"]
|
44
|
+
rescue RestClient::ResourceNotFound
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_key(key, options = {})
|
49
|
+
val = self[key]
|
50
|
+
self.store(key, val, options)
|
51
|
+
rescue RestClient::ResourceNotFound
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
def clear
|
56
|
+
@db.recreate!
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete_store
|
60
|
+
@db.delete!
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
begin
|
2
|
+
gem "dm-core", "0.9.10"
|
3
|
+
require "dm-core"
|
4
|
+
rescue LoadError
|
5
|
+
puts "You need the dm-core gem in order to use the DataMapper moneta store"
|
6
|
+
exit
|
7
|
+
end
|
8
|
+
|
9
|
+
class MonetaHash
|
10
|
+
include DataMapper::Resource
|
11
|
+
|
12
|
+
property :the_key, String, :key => true
|
13
|
+
property :value, Object, :lazy => false
|
14
|
+
property :expires, Time
|
15
|
+
|
16
|
+
def self.value(key)
|
17
|
+
obj = self.get(key)
|
18
|
+
obj && obj.value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module Moneta
|
23
|
+
class DataMapper
|
24
|
+
class Expiration
|
25
|
+
def initialize(klass, repository)
|
26
|
+
@klass = klass
|
27
|
+
@repository = repository
|
28
|
+
end
|
29
|
+
|
30
|
+
def [](key)
|
31
|
+
if obj = get(key)
|
32
|
+
obj.expires
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def []=(key, value)
|
37
|
+
obj = get(key)
|
38
|
+
obj.expires = value
|
39
|
+
obj.save(@repository)
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(key)
|
43
|
+
obj = get(key)
|
44
|
+
obj.expires = nil
|
45
|
+
obj.save(@repository)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def get(key)
|
50
|
+
repository(@repository) { @klass.get(key) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize(options = {})
|
55
|
+
@repository = options.delete(:repository) || :moneta
|
56
|
+
::DataMapper.setup(@repository, options[:setup])
|
57
|
+
repository_context { MonetaHash.auto_upgrade! }
|
58
|
+
@hash = MonetaHash
|
59
|
+
@expiration = Expiration.new(MonetaHash, @repository)
|
60
|
+
end
|
61
|
+
|
62
|
+
module Implementation
|
63
|
+
def key?(key)
|
64
|
+
repository_context { !!@hash.get(key) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def has_key?(key)
|
68
|
+
repository_context { !!@hash.get(key) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def [](key)
|
72
|
+
repository_context { @hash.value(key) }
|
73
|
+
end
|
74
|
+
|
75
|
+
def []=(key, value)
|
76
|
+
repository_context {
|
77
|
+
obj = @hash.get(key)
|
78
|
+
if obj
|
79
|
+
obj.update(key, value)
|
80
|
+
else
|
81
|
+
@hash.create(:the_key => key, :value => value)
|
82
|
+
end
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def fetch(key, value = nil)
|
87
|
+
repository_context {
|
88
|
+
value ||= block_given? ? yield(key) : default
|
89
|
+
self[key] || value
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def delete(key)
|
94
|
+
repository_context {
|
95
|
+
value = self[key]
|
96
|
+
@hash.all(:the_key => key).destroy!
|
97
|
+
value
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
def store(key, value, options = {})
|
102
|
+
repository_context { self[key] = value }
|
103
|
+
end
|
104
|
+
|
105
|
+
def clear
|
106
|
+
repository_context { @hash.all.destroy! }
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
def repository_context
|
111
|
+
repository(@repository) { yield }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
include Implementation
|
115
|
+
include Expires
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
begin
|
2
|
+
require "xattr"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the xattr gem to use the File moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
require "fileutils"
|
8
|
+
|
9
|
+
module Moneta
|
10
|
+
class File
|
11
|
+
class Expiration
|
12
|
+
def initialize(directory)
|
13
|
+
@directory = directory
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](key)
|
17
|
+
attrs = xattr(key)
|
18
|
+
ret = Marshal.load(attrs.get("moneta_expires"))
|
19
|
+
rescue Errno::ENOENT, SystemCallError
|
20
|
+
end
|
21
|
+
|
22
|
+
def []=(key, value)
|
23
|
+
attrs = xattr(key)
|
24
|
+
attrs.set("moneta_expires", Marshal.dump(value))
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete(key)
|
28
|
+
attrs = xattr(key)
|
29
|
+
attrs.remove("moneta_expires")
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def xattr(key)
|
34
|
+
::Xattr.new(::File.join(@directory, key))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(options = {})
|
39
|
+
@directory = options[:path]
|
40
|
+
if ::File.file?(@directory)
|
41
|
+
raise StandardError, "The path you supplied #{@directory} is a file"
|
42
|
+
elsif !::File.exists?(@directory)
|
43
|
+
FileUtils.mkdir_p(@directory)
|
44
|
+
end
|
45
|
+
|
46
|
+
@expiration = Expiration.new(@directory)
|
47
|
+
end
|
48
|
+
|
49
|
+
module Implementation
|
50
|
+
def key?(key)
|
51
|
+
::File.exist?(path(key))
|
52
|
+
end
|
53
|
+
|
54
|
+
alias has_key? key?
|
55
|
+
|
56
|
+
def [](key)
|
57
|
+
if ::File.exist?(path(key))
|
58
|
+
Marshal.load(::File.read(path(key)))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def []=(key, value)
|
63
|
+
::File.open(path(key), "w") do |file|
|
64
|
+
contents = Marshal.dump(value)
|
65
|
+
file.puts(contents)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def delete(key)
|
70
|
+
value = self[key]
|
71
|
+
FileUtils.rm(path(key))
|
72
|
+
value
|
73
|
+
rescue Errno::ENOENT
|
74
|
+
end
|
75
|
+
|
76
|
+
def clear
|
77
|
+
FileUtils.rm_rf(@directory)
|
78
|
+
FileUtils.mkdir(@directory)
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
def path(key)
|
83
|
+
::File.join(@directory, key.to_s)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
include Implementation
|
87
|
+
include Defaults
|
88
|
+
include Expires
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
begin
|
2
|
+
require "localmemcache"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the localmemcache gem to use the LMC moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
class Expiration
|
10
|
+
def initialize(hash)
|
11
|
+
@hash = hash
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](key) @hash["#{key}__!__expiration"] end
|
15
|
+
def []=(key, value) @hash["#{key}__!__expiration"] = value end
|
16
|
+
|
17
|
+
def delete(key)
|
18
|
+
key = "#{key}__!__expiration"
|
19
|
+
value = @hash[key]
|
20
|
+
@hash.delete(key)
|
21
|
+
value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class LMC
|
26
|
+
include Defaults
|
27
|
+
|
28
|
+
module Implementation
|
29
|
+
def initialize(options = {})
|
30
|
+
@hash = LocalMemCache.new(:filename => options[:filename])
|
31
|
+
@expiration = Expiration.new(@hash)
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](key) @hash[key] end
|
35
|
+
def []=(key, value) @hash[key] = value end
|
36
|
+
def clear() @hash.clear end
|
37
|
+
|
38
|
+
def key?(key)
|
39
|
+
@hash.keys.include?(key)
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(key)
|
43
|
+
value = @hash[key]
|
44
|
+
@hash.delete(key)
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
include Implementation
|
49
|
+
include StringExpires
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
begin
|
2
|
+
require "memcached"
|
3
|
+
MemCache = Memcached
|
4
|
+
rescue LoadError
|
5
|
+
require "memcache"
|
6
|
+
rescue
|
7
|
+
puts "You need either the `memcached` or `memcache-client` gem to use the Memcache moneta store"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
module Moneta
|
12
|
+
class Memcache
|
13
|
+
include Defaults
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
@cache = MemCache.new(options.delete(:server), options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def key?(key)
|
20
|
+
!self[key].nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
alias has_key? key?
|
24
|
+
|
25
|
+
def [](key)
|
26
|
+
@cache.get(key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def []=(key, value)
|
30
|
+
store(key, value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(key)
|
34
|
+
value = self[key]
|
35
|
+
@cache.delete(key) if value
|
36
|
+
value
|
37
|
+
end
|
38
|
+
|
39
|
+
def store(key, value, options = {})
|
40
|
+
args = [key, value, options[:expires_in]].compact
|
41
|
+
@cache.set(*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def update_key(key, options = {})
|
45
|
+
val = self[key]
|
46
|
+
self.store(key, val, options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def clear
|
50
|
+
@cache.flush_all
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
begin
|
2
|
+
require "mongo"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the mongo gem to use the MongoDB moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
class MongoDB
|
10
|
+
include Defaults
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
options = {
|
14
|
+
:host => ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
15
|
+
:port => ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT,
|
16
|
+
:db => 'cache',
|
17
|
+
:collection => 'cache'
|
18
|
+
}.update(options)
|
19
|
+
conn = XGen::Mongo::Driver::Mongo.new(options[:host], options[:port])
|
20
|
+
@cache = conn.db(options[:db]).collection(options[:collection])
|
21
|
+
end
|
22
|
+
|
23
|
+
def key?(key)
|
24
|
+
!!self[key]
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](key)
|
28
|
+
res = @cache.find_first('_id' => key)
|
29
|
+
res = nil if res && res['expires'] && Time.now > res['expires']
|
30
|
+
res && res['data']
|
31
|
+
end
|
32
|
+
|
33
|
+
def []=(key, value)
|
34
|
+
store(key, value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(key)
|
38
|
+
value = self[key]
|
39
|
+
@cache.remove('_id' => key) if value
|
40
|
+
value
|
41
|
+
end
|
42
|
+
|
43
|
+
def store(key, value, options = {})
|
44
|
+
exp = options[:expires_in] ? (Time.now + options[:expires_in]) : nil
|
45
|
+
@cache.repsert({ '_id' => key }, { '_id' => key, 'data' => value, 'expires' => exp })
|
46
|
+
end
|
47
|
+
|
48
|
+
def update_key(key, options = {})
|
49
|
+
val = self[key]
|
50
|
+
self.store(key, val, options)
|
51
|
+
end
|
52
|
+
|
53
|
+
def clear
|
54
|
+
@cache.clear
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
begin
|
2
|
+
require "redis"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the redis gem to use the Redis store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
class Redis
|
10
|
+
include Defaults
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
@cache = ::Redis.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def key?(key)
|
17
|
+
!@cache[key].nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
alias has_key? key?
|
21
|
+
|
22
|
+
def [](key)
|
23
|
+
@cache.get(key)
|
24
|
+
end
|
25
|
+
|
26
|
+
def []=(key, value)
|
27
|
+
store(key, value)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(key)
|
31
|
+
value = @cache[key]
|
32
|
+
@cache.delete(key) if value
|
33
|
+
value
|
34
|
+
end
|
35
|
+
|
36
|
+
def store(key, value, options = {})
|
37
|
+
@cache.set(key, value, options[:expires_in])
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_key(key, options = {})
|
41
|
+
val = @cache[key]
|
42
|
+
self.store(key, val, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def clear
|
46
|
+
@cache.flush_db
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
begin
|
2
|
+
require "rufus/tokyo"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You need the rufus gem to use the Rufus moneta store"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
module Moneta
|
9
|
+
class BasicRufus < ::Rufus::Tokyo::Cabinet
|
10
|
+
include Defaults
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
file = options[:file]
|
14
|
+
super("#{file}.tch")
|
15
|
+
end
|
16
|
+
|
17
|
+
def key?(key)
|
18
|
+
!!self[key]
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](key)
|
22
|
+
if val = super
|
23
|
+
Marshal.load(val.unpack("m")[0])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(key, value)
|
28
|
+
super(key, [Marshal.dump(value)].pack("m"))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Rufus < BasicRufus
|
33
|
+
include Expires
|
34
|
+
|
35
|
+
def initialize(options = {})
|
36
|
+
file = options[:file]
|
37
|
+
@expiration = BasicRufus.new(:file => "#{file}_expires")
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|