volatiledb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/volatiledb/version.rb +3 -0
- data/lib/volatiledb.rb +59 -0
- data/volatiledb.gemspec +36 -0
- metadata +60 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/volatiledb.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "volatiledb/version"
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module Volatile
|
5
|
+
|
6
|
+
class DB
|
7
|
+
def initialize
|
8
|
+
@raw ||= Volatile::Raw.new
|
9
|
+
@db ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def put(key, &action)
|
13
|
+
@db[key] = action
|
14
|
+
@raw.put(key, action.call)
|
15
|
+
key
|
16
|
+
end
|
17
|
+
|
18
|
+
def get(key)
|
19
|
+
data = @raw.get key
|
20
|
+
unless data.nil?
|
21
|
+
data
|
22
|
+
else
|
23
|
+
@raw.put(key, @db[key].call)
|
24
|
+
@raw.get(key)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Raw
|
30
|
+
def initialize
|
31
|
+
@db ||= {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def put(key, data)
|
35
|
+
handle = handle_from key
|
36
|
+
File.open("/tmp/#{handle}", "w") {|f| f << data}
|
37
|
+
@db[key] = handle
|
38
|
+
key
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(key)
|
42
|
+
handle = @db[key]
|
43
|
+
f = "/tmp/#{handle}"
|
44
|
+
if File.exists?(f)
|
45
|
+
File.read f
|
46
|
+
else
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def handle_from(key)
|
53
|
+
timestamp = Time.now.to_i
|
54
|
+
guid = Digest::SHA1.hexdigest("#{key}#{timestamp}")
|
55
|
+
"#{guid}.volatiledb"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/volatiledb.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "volatiledb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "volatiledb"
|
7
|
+
s.version = Volatile::VERSION
|
8
|
+
s.authors = ["Sebastian Wittenkamp (bitops)"]
|
9
|
+
s.email = ["a.sebastian.w@gmail.com"]
|
10
|
+
s.homepage = "http://rubygems.org/gems/volatiledb"
|
11
|
+
s.summary = %q{VolatileDB is a simple stupid storage solution for transient data on transient filesystems.}
|
12
|
+
s.description = <<DESC
|
13
|
+
The VolatileDB gem allows you to specify a key and an action yielding a particular piece of data.
|
14
|
+
|
15
|
+
This data will be stored in the /tmp folder of the file system you are currently running on. Data is accessible
|
16
|
+
by key. Data will be read and written to storage using File.read() and File.open() -- that's it. It's up to the
|
17
|
+
consuming application to serialize and deserialize data correctly. All VolatileDB does is push and pull data to
|
18
|
+
the FS.
|
19
|
+
|
20
|
+
If the underlying file supporting the data is found to be missing, it will be re-initialized.
|
21
|
+
|
22
|
+
This gets to the main idea behind VolatileDB: use it to persist data that is transient and can be re-seeded
|
23
|
+
periodically as conditions change.
|
24
|
+
DESC
|
25
|
+
|
26
|
+
s.rubyforge_project = "volatiledb"
|
27
|
+
|
28
|
+
s.files = `git ls-files`.split("\n")
|
29
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
30
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# specify any dependencies here; for example:
|
34
|
+
# s.add_development_dependency "rspec"
|
35
|
+
# s.add_runtime_dependency "rest-client"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: volatiledb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastian Wittenkamp (bitops)
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-01-04 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
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"
|
17
|
+
email:
|
18
|
+
- a.sebastian.w@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- Gemfile
|
28
|
+
- Rakefile
|
29
|
+
- lib/volatiledb.rb
|
30
|
+
- lib/volatiledb/version.rb
|
31
|
+
- volatiledb.gemspec
|
32
|
+
homepage: http://rubygems.org/gems/volatiledb
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project: volatiledb
|
55
|
+
rubygems_version: 1.8.5
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: VolatileDB is a simple stupid storage solution for transient data on transient filesystems.
|
59
|
+
test_files: []
|
60
|
+
|