rowdb 0.1.2 → 0.1.3
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 +2 -1
- data/lib/rowdb.rb +30 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dabd84303018d21818c1930fe77d0612cd50a84699507c1913f5b21ba74d7713
|
4
|
+
data.tar.gz: '038bba35d11a83ec5214fa8ef9c44c9538a604809981955c24504697590329a0'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b057c1358d2b4d96ed52b15ad5375563aa869b16a2ebe5d894ca10e78e718f35f581ff559b5b5b01681ec6bcbfd511e82bc9b7a2cc60bf2c4ac8bb6bccbb1e7a
|
7
|
+
data.tar.gz: eb0699415e0f7d1a398f393f88efbcadb1165b4e225677ac36a2616280da273aeebb5031de1d3d33a393bec76dcf0b7ae78c909b1ef7c075122268d35022e9c0
|
data/lib/adapters/FileSystem.rb
CHANGED
data/lib/rowdb.rb
CHANGED
@@ -1,31 +1,49 @@
|
|
1
|
-
require '
|
1
|
+
require 'rudash'
|
2
2
|
require_relative 'adapters/FileSystem.rb'
|
3
3
|
|
4
4
|
class Rowdb
|
5
5
|
|
6
|
-
def initialize(adapter = :file_system,
|
7
|
-
|
8
|
-
|
9
|
-
p __FILE__
|
10
|
-
p __dir__
|
11
|
-
@adapter = self.send(adapter, filepath)
|
6
|
+
def initialize(adapter = :file_system, file_path)
|
7
|
+
@adapter = self.send(adapter, normalize_path(file_path))
|
8
|
+
@data = @adapter.read()
|
12
9
|
end
|
13
10
|
|
14
11
|
def defaults(hash)
|
15
|
-
|
16
12
|
json = Oj.dump(hash)
|
17
13
|
@adapter.write(json)
|
18
|
-
|
19
14
|
end
|
20
15
|
|
21
|
-
def get(
|
16
|
+
def get(path)
|
17
|
+
R_.get(@adapter.source, path)
|
18
|
+
end
|
22
19
|
|
20
|
+
def set(path, value)
|
21
|
+
@data = R_.set(@data, path, value)
|
23
22
|
end
|
24
23
|
|
25
24
|
private
|
26
25
|
|
27
|
-
def file_system(
|
28
|
-
FileSystem.new(
|
26
|
+
def file_system(file_path)
|
27
|
+
FileSystem.new(file_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Normalize path.
|
32
|
+
#
|
33
|
+
# @param file_path - An absolute or relative path.
|
34
|
+
# @return An absolute path.
|
35
|
+
##
|
36
|
+
def normalize_path(file_path)
|
37
|
+
|
38
|
+
# Absolute path.
|
39
|
+
if file_path.start_with? '/'
|
40
|
+
return file_path
|
41
|
+
# Relative path.
|
42
|
+
else
|
43
|
+
# Get directory the script executed from.
|
44
|
+
return File.join(Dir.pwd, '/' + file_path)
|
45
|
+
end
|
46
|
+
|
29
47
|
end
|
30
48
|
|
31
49
|
end
|