json_updater 0.4.1 → 1.0.0
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/Gemfile.lock +1 -1
- data/bin/json_updater +1 -1
- data/lib/json_updater/json_full_builder.rb +10 -8
- data/lib/json_updater/json_structure_updater.rb +3 -3
- data/lib/json_updater/json_type_detector.rb +7 -7
- data/lib/json_updater/one_level_json_array_builder.rb +8 -8
- data/lib/json_updater/one_level_json_builder.rb +2 -2
- data/lib/json_updater/version.rb +1 -1
- data/lib/json_updater.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '03919c8c7fdd121ba254617667f1d16314256e7812bb6a23a1ed812a53349075'
|
4
|
+
data.tar.gz: 001606fc1801c386330ca2c7e300bbb79d389cce73be949228536f481e71f6fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 870b7922ad8be4abe52bf81a4277a41fec0f4d56a92861a506b1d57d76c283ed6d703fbf26fdeaf38e0c0313e9d019e37c02a0727049a5db57474efa50aba478
|
7
|
+
data.tar.gz: f2b296fcd83f1103be462d6de461ab1e07fc7346ea2d47c9f51d8022d84ec3194cfc9431b1921e12fece36460c5c059059c0709f47e78e40beb42fa71cb66326
|
data/Gemfile.lock
CHANGED
data/bin/json_updater
CHANGED
@@ -6,7 +6,7 @@ arg1 = JsonUpdater::JsonValidator.new(ARGV[0])
|
|
6
6
|
arg2 = JsonUpdater::JsonValidator.new(ARGV[1])
|
7
7
|
|
8
8
|
if arg1.valid? && arg2.valid?
|
9
|
-
JsonUpdater::UpdateService.update_json(ARGV[0], ARGV[1])
|
9
|
+
JsonUpdater::UpdateService.update_json(etalon_file_path: ARGV[0], changable_file_path: ARGV[1])
|
10
10
|
else
|
11
11
|
puts arg1.messages
|
12
12
|
puts arg2.messages
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
module JsonUpdater
|
4
4
|
class JsonFullBuilder
|
5
|
-
attr_reader :json_etalon, :
|
5
|
+
attr_reader :json_etalon, :json_changeable
|
6
6
|
|
7
|
-
def self.build(
|
8
|
-
new(
|
7
|
+
def self.build(json_changeable:, json_etalon:)
|
8
|
+
new(json_changeable: json_changeable, json_etalon: json_etalon).build
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@json_etalon
|
11
|
+
def initialize(json_changeable:, json_etalon:)
|
12
|
+
@json_changeable = json_changeable
|
13
|
+
@json_etalon = json_etalon
|
14
14
|
end
|
15
15
|
|
16
16
|
def build
|
17
|
-
recursion_updation(
|
17
|
+
recursion_updation(json_changeable, json_etalon)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
@@ -25,10 +25,12 @@ module JsonUpdater
|
|
25
25
|
mutation_json[etalon_field_key] = dive_inside(mutation_json[etalon_field_key], etalon_field_value)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
JsonTypeDetector.detect_type(mutation_json).build(mutation_json, inner_json_etalon)
|
28
|
+
JsonTypeDetector.detect_type(mutation_json).build(json_changeable: mutation_json, json_etalon: inner_json_etalon)
|
29
29
|
end
|
30
30
|
|
31
31
|
def dive_inside(mutation_field_value, etalon_field_value)
|
32
|
+
return etalon_field_value unless hash_or_array?(mutation_field_value)
|
33
|
+
|
32
34
|
case etalon_field_value
|
33
35
|
when Hash
|
34
36
|
recursion_updation(mutation_field_value, etalon_field_value)
|
@@ -4,11 +4,11 @@ module JsonUpdater
|
|
4
4
|
class JsonStructureUpdater
|
5
5
|
attr_reader :json_etalon, :json_changeable
|
6
6
|
|
7
|
-
def self.update_json(json_changeable
|
8
|
-
new(json_changeable, json_etalon).update_json
|
7
|
+
def self.update_json(json_changeable:, json_etalon:)
|
8
|
+
new(json_changeable: json_changeable, json_etalon: json_etalon).update_json
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(json_changeable
|
11
|
+
def initialize(json_changeable:, json_etalon:)
|
12
12
|
@json_changeable = json_changeable
|
13
13
|
@json_etalon = json_etalon.dup
|
14
14
|
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
module JsonUpdater
|
4
4
|
class JsonTypeDetector
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :json_changeable
|
6
6
|
|
7
|
-
def self.detect_type(
|
8
|
-
new(
|
7
|
+
def self.detect_type(json_changeable)
|
8
|
+
new(json_changeable).detect_type
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
11
|
+
def initialize(json_changeable)
|
12
|
+
@json_changeable = json_changeable
|
13
13
|
end
|
14
14
|
|
15
15
|
def detect_type
|
@@ -23,11 +23,11 @@ module JsonUpdater
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def one_level_json?
|
26
|
-
|
26
|
+
json_changeable.is_a?(Hash)
|
27
27
|
end
|
28
28
|
|
29
29
|
def one_level_json_array?
|
30
|
-
|
30
|
+
json_changeable.is_a?(Array)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
module JsonUpdater
|
4
4
|
class OneLevelJsonArrayBuilder
|
5
|
-
attr_reader :json_etalon, :
|
5
|
+
attr_reader :json_etalon, :json_changeable
|
6
6
|
|
7
|
-
def self.build(
|
8
|
-
new(
|
7
|
+
def self.build(json_changeable:, json_etalon:)
|
8
|
+
new(json_changeable: json_changeable, json_etalon: json_etalon).build
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@json_etalon
|
11
|
+
def initialize(json_changeable:, json_etalon:)
|
12
|
+
@json_changeable = json_changeable
|
13
|
+
@json_etalon = json_etalon
|
14
14
|
end
|
15
15
|
|
16
16
|
def build
|
17
|
-
|
18
|
-
JsonStructureUpdater.update_json(json_item, json_etalon)
|
17
|
+
json_changeable.map do |json_item|
|
18
|
+
JsonStructureUpdater.update_json(json_changeable: json_item, json_etalon: json_etalon)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module JsonUpdater
|
4
4
|
class OneLevelJsonBuilder
|
5
|
-
def self.build(
|
6
|
-
JsonStructureUpdater.update_json(
|
5
|
+
def self.build(json_changeable:, json_etalon:)
|
6
|
+
JsonStructureUpdater.update_json(json_changeable: json_changeable, json_etalon: json_etalon)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/lib/json_updater/version.rb
CHANGED
data/lib/json_updater.rb
CHANGED
@@ -13,17 +13,17 @@ require 'json_updater/json_validator'
|
|
13
13
|
|
14
14
|
module JsonUpdater
|
15
15
|
class UpdateService
|
16
|
-
attr_reader :
|
16
|
+
attr_reader :changeable_file_path, :json_changeable, :json_etalon
|
17
17
|
|
18
|
-
def self.update_json(
|
19
|
-
new(
|
18
|
+
def self.update_json(changeable_file_path:, etalon_file_path:)
|
19
|
+
new(changeable_file_path: changeable_file_path, etalon_file_path: etalon_file_path).update_json
|
20
20
|
end
|
21
21
|
|
22
|
-
def initialize(
|
23
|
-
@
|
22
|
+
def initialize(changeable_file_path:, etalon_file_path:)
|
23
|
+
@changeable_file_path = changeable_file_path
|
24
24
|
|
25
|
-
@
|
26
|
-
@json_etalon
|
25
|
+
@json_changeable = JSON.parse(File.open(changeable_file_path).read)
|
26
|
+
@json_etalon = JSON.parse(File.open(etalon_file_path).read)
|
27
27
|
end
|
28
28
|
|
29
29
|
def update_json
|
@@ -33,7 +33,7 @@ module JsonUpdater
|
|
33
33
|
private
|
34
34
|
|
35
35
|
def rewrite_file
|
36
|
-
File.open(
|
36
|
+
File.open(changeable_file_path, 'w') { |file| file.write(output_json) }
|
37
37
|
end
|
38
38
|
|
39
39
|
def output_json
|
@@ -41,7 +41,7 @@ module JsonUpdater
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def updated_json
|
44
|
-
JsonUpdater::JsonFullBuilder.build(
|
44
|
+
JsonUpdater::JsonFullBuilder.build(json_changeable: json_changeable, json_etalon: json_etalon)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_updater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladislav Hilko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|