volatiledb 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO.md +5 -4
- data/doc/Gemfile.html +94 -0
- data/doc/Rakefile.html +92 -0
- data/doc/Volatile/DB.html +366 -0
- data/doc/Volatile/Raw.html +279 -0
- data/doc/Volatile.html +165 -0
- data/doc/created.rid +5 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +78 -0
- data/doc/js/darkfish.js +116 -0
- data/doc/js/jquery.js +32 -0
- data/doc/js/quicksearch.js +114 -0
- data/doc/js/thickbox-compressed.js +10 -0
- data/doc/lib/volatiledb/version_rb.html +52 -0
- data/doc/lib/volatiledb_rb.html +56 -0
- data/doc/rdoc.css +759 -0
- data/lib/volatiledb/version.rb +5 -1
- data/lib/volatiledb.rb +36 -8
- metadata +36 -2
data/lib/volatiledb/version.rb
CHANGED
data/lib/volatiledb.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
require "volatiledb/version"
|
2
2
|
require 'digest/sha1'
|
3
3
|
|
4
|
+
#
|
5
|
+
# Main module. See DB class.
|
6
|
+
#
|
4
7
|
module Volatile
|
5
8
|
|
9
|
+
#
|
10
|
+
# The main DB class. This is the public API for the library.
|
11
|
+
#
|
6
12
|
class DB
|
13
|
+
|
14
|
+
#
|
15
|
+
# Constructor, nothing fancy.
|
16
|
+
#
|
7
17
|
def initialize
|
8
18
|
@raw ||= Volatile::Raw.new
|
9
19
|
@db ||= {}
|
@@ -13,8 +23,6 @@ module Volatile
|
|
13
23
|
# Define an action for a given key. The action should return a String.
|
14
24
|
# A timeout in seconds may optionally be defined. Default is 3 seconds.
|
15
25
|
#
|
16
|
-
# This method should be called before using any of the read operations.
|
17
|
-
#
|
18
26
|
def put(key, timeout=3, &action)
|
19
27
|
populate_db key, timeout, action
|
20
28
|
raw_put key
|
@@ -22,13 +30,15 @@ module Volatile
|
|
22
30
|
end
|
23
31
|
|
24
32
|
#
|
25
|
-
# Read the data for the given key from storage. If the underlying
|
26
|
-
# has disappeared, it will be re-initialized by calling
|
27
|
-
# for that key again. After the storage has
|
28
|
-
# will be read and returned.
|
33
|
+
# Read the data for the given key from storage. If the underlying
|
34
|
+
# storage has disappeared, it will be re-initialized by calling
|
35
|
+
# the action defined for that key again. After the storage has
|
36
|
+
# been re-initialized, its value will be read and returned.
|
37
|
+
#
|
38
|
+
# Returns nil for a key which has not had any action defined for it yet.
|
29
39
|
#
|
30
40
|
def get(key)
|
31
|
-
data =
|
41
|
+
data = raw_get key
|
32
42
|
if data.nil?
|
33
43
|
sync key
|
34
44
|
else
|
@@ -40,6 +50,8 @@ module Volatile
|
|
40
50
|
# Works the same as get, but will fire the action defined for the given key
|
41
51
|
# after the timeout defined for that key has elapsed.
|
42
52
|
#
|
53
|
+
# Returns nil for a key which has not had any action defined for it yet.
|
54
|
+
#
|
43
55
|
def fetch(key)
|
44
56
|
checking key do |k|
|
45
57
|
item = @db[k]
|
@@ -50,7 +62,10 @@ module Volatile
|
|
50
62
|
|
51
63
|
#
|
52
64
|
# Works the same as fetch, but ignores timeout and calls the defined action
|
53
|
-
# every time.
|
65
|
+
# every time. Should be used sparingly as it re-initializes storage on every
|
66
|
+
# call.
|
67
|
+
#
|
68
|
+
# Returns nil for a key which has not had any action defined for it yet.
|
54
69
|
#
|
55
70
|
def pull(key)
|
56
71
|
sync key
|
@@ -100,11 +115,21 @@ module Volatile
|
|
100
115
|
end
|
101
116
|
end
|
102
117
|
|
118
|
+
#
|
119
|
+
# Implementation detail. Not intended for direct instantiation.
|
120
|
+
#
|
103
121
|
class Raw
|
122
|
+
|
123
|
+
#
|
124
|
+
# Implementation detail.
|
125
|
+
#
|
104
126
|
def initialize
|
105
127
|
@db ||= {}
|
106
128
|
end
|
107
129
|
|
130
|
+
#
|
131
|
+
# Implementation detail.
|
132
|
+
#
|
108
133
|
def put(key, data)
|
109
134
|
handle = handle_from key
|
110
135
|
File.open("/tmp/#{handle}", "w") {|f| f << data}
|
@@ -112,6 +137,9 @@ module Volatile
|
|
112
137
|
key
|
113
138
|
end
|
114
139
|
|
140
|
+
#
|
141
|
+
# Implementation detail.
|
142
|
+
#
|
115
143
|
def get(key)
|
116
144
|
handle = @db[key]
|
117
145
|
f = "/tmp/#{handle}"
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: volatiledb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sebastian Wittenkamp (bitops)
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-01-
|
13
|
+
date: 2012-01-11 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: " The VolatileDB gem allows you to specify a key and an action yielding a particular piece of data.\n \n This data will be stored in the /tmp folder of the file system you are currently running on. Data is accessible\n by key. Data will be read and written to storage using File.read() and File.open() -- that's it. It's up to the\n consuming application to serialize and deserialize data correctly. All VolatileDB does is push and pull data to\n the FS. \n \n If the underlying file supporting the data is found to be missing, it will be re-initialized.\n \n This gets to the main idea behind VolatileDB: use it to persist data that is transient and can be re-seeded \n periodically as conditions change. \n"
|
@@ -28,6 +28,40 @@ files:
|
|
28
28
|
- README.md
|
29
29
|
- Rakefile
|
30
30
|
- TODO.md
|
31
|
+
- doc/Gemfile.html
|
32
|
+
- doc/Rakefile.html
|
33
|
+
- doc/Volatile.html
|
34
|
+
- doc/Volatile/DB.html
|
35
|
+
- doc/Volatile/Raw.html
|
36
|
+
- doc/created.rid
|
37
|
+
- doc/images/brick.png
|
38
|
+
- doc/images/brick_link.png
|
39
|
+
- doc/images/bug.png
|
40
|
+
- doc/images/bullet_black.png
|
41
|
+
- doc/images/bullet_toggle_minus.png
|
42
|
+
- doc/images/bullet_toggle_plus.png
|
43
|
+
- doc/images/date.png
|
44
|
+
- doc/images/find.png
|
45
|
+
- doc/images/loadingAnimation.gif
|
46
|
+
- doc/images/macFFBgHack.png
|
47
|
+
- doc/images/package.png
|
48
|
+
- doc/images/page_green.png
|
49
|
+
- doc/images/page_white_text.png
|
50
|
+
- doc/images/page_white_width.png
|
51
|
+
- doc/images/plugin.png
|
52
|
+
- doc/images/ruby.png
|
53
|
+
- doc/images/tag_green.png
|
54
|
+
- doc/images/wrench.png
|
55
|
+
- doc/images/wrench_orange.png
|
56
|
+
- doc/images/zoom.png
|
57
|
+
- doc/index.html
|
58
|
+
- doc/js/darkfish.js
|
59
|
+
- doc/js/jquery.js
|
60
|
+
- doc/js/quicksearch.js
|
61
|
+
- doc/js/thickbox-compressed.js
|
62
|
+
- doc/lib/volatiledb/version_rb.html
|
63
|
+
- doc/lib/volatiledb_rb.html
|
64
|
+
- doc/rdoc.css
|
31
65
|
- lib/volatiledb.rb
|
32
66
|
- lib/volatiledb/version.rb
|
33
67
|
- volatiledb.gemspec
|