rowdb 0.6.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 002f4d85a85041fb086b84afc4afca0d2f69a23db592296a9e43c0bc87e42429
4
- data.tar.gz: 7e9dffa6eacb363d53735498b791b2ddf63ecf40ad5433a910ff057703695d24
3
+ metadata.gz: 01b60ad701cb2c8829f6eb8266886e09206c7b5ae7701f6f65b457226b9801c1
4
+ data.tar.gz: fa0f8c8e78696053f1db4371958f2dad7a7676ffde40378e67677232290c9e08
5
5
  SHA512:
6
- metadata.gz: 9c8fc6df80d12dad2a8cce4cb7e9be9cda0346fb1d346e80f1d1515e6013d9fd59e09186847ba76aa6a978d9b0a398370382b7919e2e3ea0f98d4f5bfd77422b
7
- data.tar.gz: f35a9d0e10fba829d3c3ec3e77eae8ab9aab547f94f0cb4a770c51e70741176a649eabc83290d37b9d0c49111975074f2757f4b307fbc822487b893a31415333
6
+ metadata.gz: b4b886394e59f1f0bd01462ba938c18afeb017d94088a41a4b9c7147fae7f57069acde07c26fd30e302e1a2f367a024668abcfe50d82c84a7848a90caaba13c8
7
+ data.tar.gz: 7243829e5c96dcb28c7be102f4e913ad7bfae2662747df03ba83480b30d761d4b7b98b9bbc5cff64584cbf9473808c72d33a4075a3f8e5bd86f56dcb87b651db
@@ -53,10 +53,21 @@ class Adapter
53
53
  #
54
54
  # @param String json
55
55
  ##
56
- def wrap(json)
56
+ def wrap()
57
57
 
58
- json.prepend(@prefix)
59
- json << @suffix
58
+ new_file = ""
59
+
60
+ # Open file.
61
+ File.open(@source, 'r') do |file|
62
+ new_file = file.read
63
+ new_file.prepend(@prefix)
64
+ new_file << @suffix
65
+ end
66
+
67
+ # Overwrite file.
68
+ File.open(@source, 'w') do |file|
69
+ file.write(new_file)
70
+ end
60
71
 
61
72
  end
62
73
 
@@ -67,8 +78,11 @@ class Adapter
67
78
  ##
68
79
  def unwrap(json)
69
80
 
70
- json.delete_prefix!(@prefix)
71
- json.delete_suffix!(@suffix)
81
+ # Deletes: var data = \"
82
+ json.delete_prefix!(@prefix + '"')
83
+
84
+ # Deletes: \";
85
+ json.delete_suffix!('"' + @suffix)
72
86
 
73
87
  end
74
88
 
@@ -13,13 +13,22 @@ class Sync < Adapter
13
13
  ##
14
14
  def read()
15
15
 
16
- json = Oj.load_file(@source)
17
-
18
- unless json.nil?
19
-
20
- if @format == :js
16
+ json = nil
17
+
18
+ # Load JSON inside a Javascript variable.
19
+ if @format == :js && File.exist?(@source)
20
+ File.open(@source, 'r') do |file|
21
+ json = file.read
22
+ # Fix double encoding issue due to JSON string becoming Ruby string.
23
+ json.gsub!('\\"', '"')
21
24
  unwrap(json)
22
25
  end
26
+ # Load JSON string.
27
+ else
28
+ json = Oj.load_file(@source)
29
+ end
30
+
31
+ unless json.nil?
23
32
 
24
33
  # Parse JSON.
25
34
  data = Oj.load(json)
@@ -40,12 +49,12 @@ class Sync < Adapter
40
49
 
41
50
  json = Oj.dump(data, mode: :compat)
42
51
 
52
+ Oj.to_file(@source, json)
53
+
43
54
  if @format == :js
44
- wrap(json)
55
+ wrap()
45
56
  end
46
57
 
47
- Oj.to_file(@source, json)
48
-
49
58
  end
50
59
 
51
60
  end
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.6.0
4
+ version: 0.6.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-10-14 00:00:00.000000000 Z
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj