ssd 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ssd.rb +3 -7
- data/lib/ssd/class_methods.rb +62 -60
- data/lib/ssd/instance_methods.rb +37 -33
- data/lib/ssd/internals.rb +10 -0
- data/lib/ssd/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f412d9d7275b088771b8f1d3e27c5a5a491e9578
|
4
|
+
data.tar.gz: 51fbff3062486cc2afebb78809b689432a815d47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daf9d2a958b82531af90c845b385e4b9b820e9e8351e07becce4d1dc7ca733344d418d575ad9b6979cda70caf36a0a9229c3b62e1fe7bcec491e36fdce134346
|
7
|
+
data.tar.gz: b9ca75641c32bafe80bce22d1a2c0660525463d5fa6982c0ef7c83d8916fc90b1a298048d224c70ad2931d5214c7f97609febff068934655ae5bb5f1aa7ffa92
|
data/lib/ssd.rb
CHANGED
@@ -5,17 +5,13 @@ require 'pstore'
|
|
5
5
|
require 'digest'
|
6
6
|
|
7
7
|
require_relative "./ssd/version"
|
8
|
-
require_relative "./ssd/
|
9
|
-
require_relative "./ssd/class_methods"
|
10
|
-
|
8
|
+
require_relative "./ssd/internals"
|
11
9
|
$log = Logger.new(STDOUT)
|
12
10
|
|
13
11
|
module SSD
|
14
|
-
attr_reader :db
|
15
|
-
attr_reader :path
|
16
12
|
|
17
13
|
def self.included(base)
|
18
|
-
base.send :include, InstanceMethods
|
19
|
-
base.extend ClassMethods
|
14
|
+
base.send :include, SSD::Internals::InstanceMethods
|
15
|
+
base.extend SSD::Internals::ClassMethods
|
20
16
|
end
|
21
17
|
end
|
data/lib/ssd/class_methods.rb
CHANGED
@@ -1,81 +1,83 @@
|
|
1
1
|
module SSD
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
2
|
+
module Internals
|
3
|
+
module ClassMethods
|
4
|
+
def self.extended(base)
|
5
|
+
@@ssd_name = base.new.class.to_s.downcase
|
6
|
+
#FileUtils::mkdir_p 'DS'
|
7
|
+
#@@ssd_path = "DS/#{name}.pstore"
|
8
|
+
#@@ssd_db = PStore.new @@ssd_path, true
|
9
|
+
#@@ssd_db.ultra_safe = true
|
10
|
+
#@@ssd_db.transaction(true) {}
|
11
|
+
#@@ssd_db
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def setup ssd
|
15
|
+
@@ssd = ssd
|
16
|
+
FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
|
17
|
+
@@ssd_path = ".ssd/#{@@ssd_name}/#{@@ssd}.ssd"
|
18
|
+
@@ssd_db = PStore.new @@ssd_path, true
|
19
|
+
@@ssd_db.ultra_safe = true
|
20
|
+
@@ssd_db.transaction(true) {}
|
21
|
+
return @@ssd_db
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
def last_key ssd
|
25
|
+
setup ssd
|
26
|
+
last_key = @@ssd_db.transaction true do
|
27
|
+
@@ssd_db.roots
|
28
|
+
end
|
29
|
+
last_key.last
|
27
30
|
end
|
28
|
-
last_key.last
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def keys ssd
|
33
|
+
setup ssd
|
34
|
+
@@ssd_db.transaction true do
|
35
|
+
@@ssd_db.roots
|
36
|
+
end
|
35
37
|
end
|
36
|
-
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
def key? ssd
|
40
|
+
setup ssd
|
41
|
+
@@ssd_db.transaction true do
|
42
|
+
@@ssd_db.root? ssd
|
43
|
+
end
|
42
44
|
end
|
43
|
-
end
|
44
45
|
|
45
|
-
|
46
|
+
alias exists? key?
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
def [] ssd
|
49
|
+
setup ssd
|
50
|
+
@@ssd_db.transaction true do
|
51
|
+
@@ssd_db[ssd]
|
52
|
+
end
|
51
53
|
end
|
52
|
-
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
def ssd ssd, default = nil
|
56
|
+
#TODO add raise if ssd.nil?
|
57
|
+
last_key = (last_key ssd)
|
58
|
+
@@ssd_db.transaction true do
|
59
|
+
@@ssd_db.fetch last_key, default
|
60
|
+
end
|
59
61
|
end
|
60
|
-
end
|
61
62
|
|
62
|
-
|
63
|
-
|
63
|
+
#alias get ssd
|
64
|
+
#alias find ssd
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
def delete *ssds
|
67
|
+
@@ssd_db.transaction do
|
68
|
+
ssds.each do |ssd|
|
69
|
+
@@ssd_db.delete ssd.to_sym
|
70
|
+
end
|
71
|
+
@@ssd_db.commit
|
69
72
|
end
|
70
|
-
@@ssd_db.commit
|
71
73
|
end
|
72
|
-
|
73
|
-
alias remove delete
|
74
|
+
alias remove delete
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
def count ssd
|
77
|
+
setup ssd
|
78
|
+
$log.info("count")
|
79
|
+
return keys(ssd).count
|
80
|
+
end
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|
data/lib/ssd/instance_methods.rb
CHANGED
@@ -1,44 +1,48 @@
|
|
1
1
|
module SSD
|
2
|
-
module
|
2
|
+
module Internals
|
3
|
+
module InstanceMethods
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
def self.included(base)
|
6
|
+
@@ssd_name = base.new.class.to_s.downcase
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
+
attr_accessor :ssd
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
def ssd= value
|
12
|
+
@ssd = value
|
13
|
+
FileUtils::mkdir_p ".ssd/#{@@ssd_name}"
|
14
|
+
@@ssd_path = ".ssd/#{@@ssd_name}/#{@ssd}.ssd"
|
15
|
+
@@ssd_db = PStore.new @@ssd_path, true
|
16
|
+
@@ssd_db.ultra_safe = true
|
17
|
+
@@ssd_db.transaction(true) {}
|
18
|
+
return @@ssd_db
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def transaction
|
22
|
+
@@ssd_db.transaction do
|
23
|
+
yield @@ssd_db
|
24
|
+
@@ssd_db.commit
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@@ssd_db
|
28
|
+
def []=
|
29
|
+
@@ssd_path = ".ssd/#{@@ssd_name}/#{@ssd}.ssd"
|
30
|
+
@@ssd_db = PStore.new @@ssd_path, true
|
31
|
+
begin
|
32
|
+
if !@ssd.nil? then
|
33
|
+
@@ssd_db.transaction do
|
34
|
+
#todo should be somthing like??? timestamp instead of ssd as a key?? and use .last while reading
|
35
|
+
@@ssd_db[Time.now.utc.to_s + "_" + Random.new_seed.to_s ] = self
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise 'ssd key can not be nil. see more (documentation url)'
|
33
39
|
end
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
40
|
+
end
|
41
|
+
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
alias append! []=
|
44
|
+
alias save! []=
|
45
|
+
alias store! []=
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
data/lib/ssd/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zotherstupidguy
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/ssd/class_methods.rb
|
74
74
|
- lib/ssd/encrypt.rb
|
75
75
|
- lib/ssd/instance_methods.rb
|
76
|
+
- lib/ssd/internals.rb
|
76
77
|
- lib/ssd/version.rb
|
77
78
|
- logo.png
|
78
79
|
- ssd.gemspec
|