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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0825d84e4c81d08aff287bb4ec45ad3c076b652d
4
- data.tar.gz: 273829d0588557664e5afbd900ed28b38b59857b
3
+ metadata.gz: f412d9d7275b088771b8f1d3e27c5a5a491e9578
4
+ data.tar.gz: 51fbff3062486cc2afebb78809b689432a815d47
5
5
  SHA512:
6
- metadata.gz: a619969e3f149af20609c169b22bfff7c74aba7c192d98a5c2aa14d4c1c1808b61b116777a628a0d46ea2da72f11ce2635cc92842a521a4cf469d4bef02fa173
7
- data.tar.gz: 1f2f0d24e6bc7189cf6721df3d333a21ad006324b5f8303c981c88fa20bdda768db4ca2f619a80422f716e5c24d61367b759e7640d8dbc98dbd32a07991dea07
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/instance_methods"
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
@@ -1,81 +1,83 @@
1
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
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
- 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
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
- def last_key ssd
24
- setup ssd
25
- last_key = @@ssd_db.transaction true do
26
- @@ssd_db.roots
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
- def keys ssd
32
- setup ssd
33
- @@ssd_db.transaction true do
34
- @@ssd_db.roots
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
- def key? ssd
39
- setup ssd
40
- @@ssd_db.transaction true do
41
- @@ssd_db.root? ssd
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
- alias exists? key?
46
+ alias exists? key?
46
47
 
47
- def [] ssd
48
- setup ssd
49
- @@ssd_db.transaction true do
50
- @@ssd_db[ssd]
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
- 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
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
- #alias get ssd
63
- #alias find ssd
63
+ #alias get ssd
64
+ #alias find ssd
64
65
 
65
- def delete *ssds
66
- @@ssd_db.transaction do
67
- ssds.each do |ssd|
68
- @@ssd_db.delete ssd.to_sym
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
- end
73
- alias remove delete
74
+ alias remove delete
74
75
 
75
- def count ssd
76
- setup ssd
77
- $log.info("count")
78
- return keys(ssd).count
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
@@ -1,44 +1,48 @@
1
1
  module SSD
2
- module InstanceMethods
2
+ module Internals
3
+ module InstanceMethods
3
4
 
4
- def self.included(base)
5
- @@ssd_name = base.new.class.to_s.downcase
6
- end
5
+ def self.included(base)
6
+ @@ssd_name = base.new.class.to_s.downcase
7
+ end
7
8
 
8
- attr_accessor :ssd
9
+ attr_accessor :ssd
9
10
 
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
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
- def transaction
21
- @@ssd_db.transaction do
22
- yield @@ssd_db
23
- @@ssd_db.commit
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
- 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
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
- else
35
- raise 'ssd key can not be nil. see more (documentation url)'
36
- end
37
- end
38
- end
40
+ end
41
+ end
39
42
 
40
- alias append! []=
41
- alias save! []=
42
- alias store! []=
43
+ alias append! []=
44
+ alias save! []=
45
+ alias store! []=
46
+ end
43
47
  end
44
48
  end
@@ -0,0 +1,10 @@
1
+ require_relative "./instance_methods"
2
+ require_relative "./class_methods"
3
+
4
+ module SSD
5
+ module Internals
6
+ attr_reader :db
7
+ attr_reader :path
8
+
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module SSD
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
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.6
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