rowdb 0.1.4 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/adapters/{FileSystem.rb → Sync.rb} +7 -3
- data/lib/rowdb.rb +39 -13
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c1806858f1a8d306f1ee05349654b9d368a8236f67ac980263639a0ba799b5
|
4
|
+
data.tar.gz: 128eb45b82377dc04fa2ea226c1f962f18a494e7778f8da83c2fd0eaa0fa18cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3c28ad22face7a22ed466bfe3d61b2c82ef8aee4a22d8d275979b4d9bbbaa9bef9b7b1b32150449f321b3ed4ab745e52fe7cc48df27049b917d8f94c36da175
|
7
|
+
data.tar.gz: dd270b13e87c11753d2cdc50baf277c45cdd9fb637448e740ba3caeca40be4c107797b38fa9073b6bd71f3316d6462779d4e051849b566ccef55bd25c454d45f
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'oj'
|
2
2
|
require_relative 'Adapter.rb'
|
3
3
|
|
4
|
-
|
4
|
+
##
|
5
|
+
# Synchronous file system.
|
6
|
+
##
|
7
|
+
class Sync < Adapter
|
5
8
|
|
6
9
|
##
|
7
10
|
# Load a JSON string from a file.
|
@@ -13,7 +16,8 @@ class FileSystem < Adapter
|
|
13
16
|
json = Oj.load_file(@source)
|
14
17
|
|
15
18
|
unless json.nil?
|
16
|
-
|
19
|
+
data = Oj.load(json)
|
20
|
+
return data.transform_keys(&:to_sym)
|
17
21
|
end
|
18
22
|
|
19
23
|
return nil
|
@@ -27,7 +31,7 @@ class FileSystem < Adapter
|
|
27
31
|
##
|
28
32
|
def write(data)
|
29
33
|
|
30
|
-
json = Oj.dump(data)
|
34
|
+
json = Oj.dump(data, mode: :compat)
|
31
35
|
Oj.to_file(@source, json)
|
32
36
|
|
33
37
|
end
|
data/lib/rowdb.rb
CHANGED
@@ -1,35 +1,61 @@
|
|
1
1
|
require 'rudash'
|
2
|
-
require_relative 'adapters/
|
2
|
+
require_relative 'adapters/Sync.rb'
|
3
3
|
|
4
4
|
class Rowdb
|
5
5
|
|
6
|
-
def initialize(adapter = :
|
6
|
+
def initialize(file_path, adapter = :sync)
|
7
7
|
@adapter = self.send(adapter, normalize_path(file_path))
|
8
|
-
@
|
8
|
+
@chain = R_.chain(@adapter.read())
|
9
|
+
@get_path = nil
|
9
10
|
end
|
10
11
|
|
12
|
+
# Set default data.
|
11
13
|
def defaults(data)
|
12
|
-
if @
|
13
|
-
|
14
|
-
@data = data
|
15
|
-
# Save data to disk.
|
16
|
-
@adapter.write(data)
|
14
|
+
if @chain.value().nil?
|
15
|
+
@chain = R_.chain(data.transform_keys(&:to_sym))
|
17
16
|
end
|
17
|
+
self
|
18
18
|
end
|
19
19
|
|
20
20
|
def get(path)
|
21
|
-
|
21
|
+
@get_path = path
|
22
|
+
@chain.get(path)
|
23
|
+
self
|
22
24
|
end
|
23
25
|
|
24
26
|
def set(path, value)
|
25
|
-
@
|
26
|
-
|
27
|
+
@chain.set(path, value)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def value()
|
32
|
+
@chain.value()
|
33
|
+
end
|
34
|
+
|
35
|
+
def push(value)
|
36
|
+
|
37
|
+
if @get_path.nil?
|
38
|
+
raise StandardError.new "You must get() before push()."
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add value to end of array.
|
42
|
+
adder = -> (items) {
|
43
|
+
[*items, value]
|
44
|
+
}
|
45
|
+
R_.update(@chain.value(), @get_path, adder)
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def write()
|
51
|
+
@adapter.write(@chain.value())
|
52
|
+
self
|
27
53
|
end
|
28
54
|
|
29
55
|
private
|
30
56
|
|
31
|
-
def
|
32
|
-
|
57
|
+
def sync(file_path)
|
58
|
+
Sync.new(file_path)
|
33
59
|
end
|
34
60
|
|
35
61
|
##
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rowdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maedi Prichard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -38,16 +38,17 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description: A local JSON database for Ruby inspired by lowdb
|
41
|
+
description: A local JSON database for Ruby inspired by lowdb, using Rudash for easy
|
42
|
+
Hash traversal.
|
42
43
|
email: maediprichard@gmailcom
|
43
44
|
executables: []
|
44
45
|
extensions: []
|
45
46
|
extra_rdoc_files: []
|
46
47
|
files:
|
47
48
|
- lib/adapters/Adapter.rb
|
48
|
-
- lib/adapters/
|
49
|
+
- lib/adapters/Sync.rb
|
49
50
|
- lib/rowdb.rb
|
50
|
-
homepage: https://github.com/
|
51
|
+
homepage: https://github.com/rowdb/rowdb
|
51
52
|
licenses:
|
52
53
|
- MPL-2.0
|
53
54
|
metadata: {}
|