ssd 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/lib/ssd.rb +2 -124
- data/lib/ssd/class_methods.rb +81 -0
- data/lib/{encrypt.rb → ssd/encrypt.rb} +0 -0
- data/lib/ssd/instance_methods.rb +44 -0
- data/lib/ssd/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0825d84e4c81d08aff287bb4ec45ad3c076b652d
|
4
|
+
data.tar.gz: 273829d0588557664e5afbd900ed28b38b59857b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a619969e3f149af20609c169b22bfff7c74aba7c192d98a5c2aa14d4c1c1808b61b116777a628a0d46ea2da72f11ce2635cc92842a521a4cf469d4bef02fa173
|
7
|
+
data.tar.gz: 1f2f0d24e6bc7189cf6721df3d333a21ad006324b5f8303c981c88fa20bdda768db4ca2f619a80422f716e5c24d61367b759e7640d8dbc98dbd32a07991dea07
|
data/README.md
CHANGED
@@ -4,12 +4,11 @@ SSD is an append-only, file-based, immutable key-value store for Microservices w
|
|
4
4
|
|
5
5
|
Key Features
|
6
6
|
=================
|
7
|
-
- **Scalable** file-based design
|
7
|
+
- **Scalable** via a schemaless, thread-safe, file-based design that easily meets your data evolution needs.
|
8
8
|
- **Immutable Append-only** tracks data evolution over time via out-of-the-box UTC timestamped appends (*accountants don't use erasers, otherwise they go to jail*).
|
9
9
|
- **Fault Tolerance** (out-of-the-box transactional operations).
|
10
|
-
- **Zero External Dependencies for a Measurably Low Technical Debt** (a well-maintained consciously clean lightweight library that prioritizes the sanity of your codebase and takes measures to **NEVER** complect it).
|
11
|
-
- **
|
12
|
-
- **Key-based Rolling-forward\Rolling-back**.
|
10
|
+
- **Zero External Dependencies for a Measurably Low Technical Debt** (a well-maintained, consciously clean, lightweight library that prioritizes the sanity of your codebase and takes measures to **NEVER** complect it).
|
11
|
+
- **Key-based Forward\Backward Rolling**.
|
13
12
|
- **Super Easy to Learn and Use** (up & running in mins).
|
14
13
|
|
15
14
|
TODO
|
@@ -28,7 +27,14 @@ SSD is carefully crafted to scale specially-well with the Microservies Architetu
|
|
28
27
|
|
29
28
|
Usage
|
30
29
|
======
|
30
|
+
```
|
31
|
+
gem install ssd
|
32
|
+
```
|
33
|
+
|
31
34
|
```ruby
|
35
|
+
require 'sinatra'
|
36
|
+
require 'ssd'
|
37
|
+
|
32
38
|
module MyApp
|
33
39
|
class User
|
34
40
|
include SSD
|
data/lib/ssd.rb
CHANGED
@@ -5,6 +5,8 @@ require 'pstore'
|
|
5
5
|
require 'digest'
|
6
6
|
|
7
7
|
require_relative "./ssd/version"
|
8
|
+
require_relative "./ssd/instance_methods"
|
9
|
+
require_relative "./ssd/class_methods"
|
8
10
|
|
9
11
|
$log = Logger.new(STDOUT)
|
10
12
|
|
@@ -16,128 +18,4 @@ module SSD
|
|
16
18
|
base.send :include, InstanceMethods
|
17
19
|
base.extend ClassMethods
|
18
20
|
end
|
19
|
-
|
20
|
-
module InstanceMethods
|
21
|
-
|
22
|
-
def self.included(base)
|
23
|
-
@@ssd_name = base.new.class.to_s.downcase
|
24
|
-
end
|
25
|
-
|
26
|
-
attr_accessor :ssd
|
27
|
-
|
28
|
-
def ssd= value
|
29
|
-
@ssd = value
|
30
|
-
FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
|
31
|
-
@@ssd_path = ".ssd/#{@@ssd_name}/#{@ssd}.ssd"
|
32
|
-
@@ssd_db = PStore.new @@ssd_path, true
|
33
|
-
@@ssd_db.ultra_safe = true
|
34
|
-
@@ssd_db.transaction(true) {}
|
35
|
-
return @@ssd_db
|
36
|
-
end
|
37
|
-
|
38
|
-
def transaction
|
39
|
-
@@ssd_db.transaction do
|
40
|
-
yield @@ssd_db
|
41
|
-
@@ssd_db.commit
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def []=
|
46
|
-
begin
|
47
|
-
if !@ssd.nil? then
|
48
|
-
@@ssd_db.transaction do
|
49
|
-
#todo should be somthing like??? timestamp instead of ssd as a key?? and use .last while reading
|
50
|
-
@@ssd_db[Time.now.utc.to_s + "_" + Random.new_seed.to_s ] = self
|
51
|
-
end
|
52
|
-
else
|
53
|
-
raise 'ssd key can not be nil. see more (documentation url)'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
alias append! []=
|
59
|
-
alias save! []=
|
60
|
-
alias store! []=
|
61
|
-
end
|
62
|
-
|
63
|
-
module ClassMethods
|
64
|
-
def self.extended(base)
|
65
|
-
@@ssd_name = base.new.class.to_s.downcase
|
66
|
-
#FileUtils::mkdir_p 'DS'
|
67
|
-
#@@ssd_path = "DS/#{name}.pstore"
|
68
|
-
#@@ssd_db = PStore.new @@ssd_path, true
|
69
|
-
#@@ssd_db.ultra_safe = true
|
70
|
-
#@@ssd_db.transaction(true) {}
|
71
|
-
#@@ssd_db
|
72
|
-
end
|
73
|
-
|
74
|
-
def setup ssd
|
75
|
-
@@ssd = ssd
|
76
|
-
FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
|
77
|
-
@@ssd_path = ".ssd/#{@@ssd_name}/#{@@ssd}.ssd"
|
78
|
-
@@ssd_db = PStore.new @@ssd_path, true
|
79
|
-
@@ssd_db.ultra_safe = true
|
80
|
-
@@ssd_db.transaction(true) {}
|
81
|
-
return @@ssd_db
|
82
|
-
end
|
83
|
-
|
84
|
-
def last_key ssd
|
85
|
-
setup ssd
|
86
|
-
last_key = @@ssd_db.transaction true do
|
87
|
-
@@ssd_db.roots
|
88
|
-
end
|
89
|
-
last_key.last
|
90
|
-
end
|
91
|
-
|
92
|
-
def keys ssd
|
93
|
-
setup ssd
|
94
|
-
@@ssd_db.transaction true do
|
95
|
-
@@ssd_db.roots
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def key? ssd
|
100
|
-
setup ssd
|
101
|
-
@@ssd_db.transaction true do
|
102
|
-
@@ssd_db.root? ssd
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
alias exists? key?
|
107
|
-
|
108
|
-
def [] ssd
|
109
|
-
setup ssd
|
110
|
-
@@ssd_db.transaction true do
|
111
|
-
@@ssd_db[ssd]
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def ssd ssd, default = nil
|
116
|
-
#TODO add raise if ssd.nil?
|
117
|
-
last_key = (last_key ssd)
|
118
|
-
@@ssd_db.transaction true do
|
119
|
-
@@ssd_db.fetch last_key, default
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
#alias get ssd
|
124
|
-
#alias find ssd
|
125
|
-
|
126
|
-
def delete *ssds
|
127
|
-
@@ssd_db.transaction do
|
128
|
-
ssds.each do |ssd|
|
129
|
-
@@ssd_db.delete ssd.to_sym
|
130
|
-
end
|
131
|
-
@@ssd_db.commit
|
132
|
-
end
|
133
|
-
end
|
134
|
-
alias remove delete
|
135
|
-
|
136
|
-
def count ssd
|
137
|
-
setup ssd
|
138
|
-
$log.info("count")
|
139
|
-
return keys(ssd).count
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
21
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module SSD
|
2
|
+
module ClassMethods
|
3
|
+
def self.extended(base)
|
4
|
+
@@ssd_name = base.new.class.to_s.downcase
|
5
|
+
#FileUtils::mkdir_p 'DS'
|
6
|
+
#@@ssd_path = "DS/#{name}.pstore"
|
7
|
+
#@@ssd_db = PStore.new @@ssd_path, true
|
8
|
+
#@@ssd_db.ultra_safe = true
|
9
|
+
#@@ssd_db.transaction(true) {}
|
10
|
+
#@@ssd_db
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup ssd
|
14
|
+
@@ssd = ssd
|
15
|
+
FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
|
16
|
+
@@ssd_path = ".ssd/#{@@ssd_name}/#{@@ssd}.ssd"
|
17
|
+
@@ssd_db = PStore.new @@ssd_path, true
|
18
|
+
@@ssd_db.ultra_safe = true
|
19
|
+
@@ssd_db.transaction(true) {}
|
20
|
+
return @@ssd_db
|
21
|
+
end
|
22
|
+
|
23
|
+
def last_key ssd
|
24
|
+
setup ssd
|
25
|
+
last_key = @@ssd_db.transaction true do
|
26
|
+
@@ssd_db.roots
|
27
|
+
end
|
28
|
+
last_key.last
|
29
|
+
end
|
30
|
+
|
31
|
+
def keys ssd
|
32
|
+
setup ssd
|
33
|
+
@@ssd_db.transaction true do
|
34
|
+
@@ssd_db.roots
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def key? ssd
|
39
|
+
setup ssd
|
40
|
+
@@ssd_db.transaction true do
|
41
|
+
@@ssd_db.root? ssd
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
alias exists? key?
|
46
|
+
|
47
|
+
def [] ssd
|
48
|
+
setup ssd
|
49
|
+
@@ssd_db.transaction true do
|
50
|
+
@@ssd_db[ssd]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def ssd ssd, default = nil
|
55
|
+
#TODO add raise if ssd.nil?
|
56
|
+
last_key = (last_key ssd)
|
57
|
+
@@ssd_db.transaction true do
|
58
|
+
@@ssd_db.fetch last_key, default
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#alias get ssd
|
63
|
+
#alias find ssd
|
64
|
+
|
65
|
+
def delete *ssds
|
66
|
+
@@ssd_db.transaction do
|
67
|
+
ssds.each do |ssd|
|
68
|
+
@@ssd_db.delete ssd.to_sym
|
69
|
+
end
|
70
|
+
@@ssd_db.commit
|
71
|
+
end
|
72
|
+
end
|
73
|
+
alias remove delete
|
74
|
+
|
75
|
+
def count ssd
|
76
|
+
setup ssd
|
77
|
+
$log.info("count")
|
78
|
+
return keys(ssd).count
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
File without changes
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SSD
|
2
|
+
module InstanceMethods
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
@@ssd_name = base.new.class.to_s.downcase
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :ssd
|
9
|
+
|
10
|
+
def ssd= value
|
11
|
+
@ssd = value
|
12
|
+
FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
|
13
|
+
@@ssd_path = ".ssd/#{@@ssd_name}/#{@ssd}.ssd"
|
14
|
+
@@ssd_db = PStore.new @@ssd_path, true
|
15
|
+
@@ssd_db.ultra_safe = true
|
16
|
+
@@ssd_db.transaction(true) {}
|
17
|
+
return @@ssd_db
|
18
|
+
end
|
19
|
+
|
20
|
+
def transaction
|
21
|
+
@@ssd_db.transaction do
|
22
|
+
yield @@ssd_db
|
23
|
+
@@ssd_db.commit
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=
|
28
|
+
begin
|
29
|
+
if !@ssd.nil? then
|
30
|
+
@@ssd_db.transaction do
|
31
|
+
#todo should be somthing like??? timestamp instead of ssd as a key?? and use .last while reading
|
32
|
+
@@ssd_db[Time.now.utc.to_s + "_" + Random.new_seed.to_s ] = self
|
33
|
+
end
|
34
|
+
else
|
35
|
+
raise 'ssd key can not be nil. see more (documentation url)'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
alias append! []=
|
41
|
+
alias save! []=
|
42
|
+
alias store! []=
|
43
|
+
end
|
44
|
+
end
|
data/lib/ssd/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zotherstupidguy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09
|
11
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,8 +69,10 @@ files:
|
|
69
69
|
- bin/console
|
70
70
|
- bin/repl.rb
|
71
71
|
- bin/setup
|
72
|
-
- lib/encrypt.rb
|
73
72
|
- lib/ssd.rb
|
73
|
+
- lib/ssd/class_methods.rb
|
74
|
+
- lib/ssd/encrypt.rb
|
75
|
+
- lib/ssd/instance_methods.rb
|
74
76
|
- lib/ssd/version.rb
|
75
77
|
- logo.png
|
76
78
|
- ssd.gemspec
|
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
96
|
version: '0'
|
95
97
|
requirements: []
|
96
98
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.6.7
|
98
100
|
signing_key:
|
99
101
|
specification_version: 4
|
100
102
|
summary: SSD is an append-only, file-based, immutable key-value store for Microservices
|