json_updater 0.4.1 → 1.0.0

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
  SHA256:
3
- metadata.gz: 1369c256030d09acbe23c4e948b7e933bc37edcd8d7af20d27ccd9ded600ad19
4
- data.tar.gz: 6dc9e09847b8d7ef18059c9037620ab743d40e4009d0a00522f180b94d70f484
3
+ metadata.gz: '03919c8c7fdd121ba254617667f1d16314256e7812bb6a23a1ed812a53349075'
4
+ data.tar.gz: 001606fc1801c386330ca2c7e300bbb79d389cce73be949228536f481e71f6fa
5
5
  SHA512:
6
- metadata.gz: 9cbe6d11c86ef64586cf2693db4bc1f7f486e8b12ad6a8c3a1724b9bb598d94d6736c7d92071d71c2f1a5d389378db63c1ab3dec26087c4b9c1476de912b5429
7
- data.tar.gz: fc8b7cc124aa5c789f263f2d1d9ac8a0b8208da2a8cb0b381c6eec2e561983eeb418dcd6e8870ce65c5177bdeb4493daf4ff2e6fcfb9d7e79de9483034ccd433
6
+ metadata.gz: 870b7922ad8be4abe52bf81a4277a41fec0f4d56a92861a506b1d57d76c283ed6d703fbf26fdeaf38e0c0313e9d019e37c02a0727049a5db57474efa50aba478
7
+ data.tar.gz: f2b296fcd83f1103be462d6de461ab1e07fc7346ea2d47c9f51d8022d84ec3194cfc9431b1921e12fece36460c5c059059c0709f47e78e40beb42fa71cb66326
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- json_updater (0.4.1)
4
+ json_updater (1.0.0)
5
5
  json
6
6
 
7
7
  GEM
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, :json_changeble
5
+ attr_reader :json_etalon, :json_changeable
6
6
 
7
- def self.build(json_changeble, json_etalon)
8
- new(json_changeble, json_etalon).build
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(json_changeble, json_etalon)
12
- @json_changeble = json_changeble
13
- @json_etalon = 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(json_changeble, json_etalon)
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, json_etalon)
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, json_etalon)
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 :json_changeble
5
+ attr_reader :json_changeable
6
6
 
7
- def self.detect_type(json_changeble)
8
- new(json_changeble).detect_type
7
+ def self.detect_type(json_changeable)
8
+ new(json_changeable).detect_type
9
9
  end
10
10
 
11
- def initialize(json_changeble)
12
- @json_changeble = json_changeble
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
- json_changeble.is_a?(Hash)
26
+ json_changeable.is_a?(Hash)
27
27
  end
28
28
 
29
29
  def one_level_json_array?
30
- json_changeble.is_a?(Array)
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, :json_changeble
5
+ attr_reader :json_etalon, :json_changeable
6
6
 
7
- def self.build(json_changeble, json_etalon)
8
- new(json_changeble, json_etalon).build
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(json_changeble, json_etalon)
12
- @json_changeble = json_changeble
13
- @json_etalon = 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
- json_changeble.map do |json_item|
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(json_changeble, json_etalon)
6
- JsonStructureUpdater.update_json(json_changeble, json_etalon)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonUpdater
4
- VERSION = '0.4.1'
4
+ VERSION = '1.0.0'
5
5
  end
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 :changable_file_path, :json_changeble, :json_etalon
16
+ attr_reader :changeable_file_path, :json_changeable, :json_etalon
17
17
 
18
- def self.update_json(changable_file_path, etalon_file_path)
19
- new(changable_file_path, etalon_file_path).update_json
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(changable_file_path, etalon_file_path)
23
- @changable_file_path = changable_file_path
22
+ def initialize(changeable_file_path:, etalon_file_path:)
23
+ @changeable_file_path = changeable_file_path
24
24
 
25
- @json_changeble = JSON.parse(File.open(changable_file_path).read)
26
- @json_etalon = JSON.parse(File.open(etalon_file_path).read)
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(changable_file_path, 'w') { |file| file.write(output_json) }
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(json_changeble, json_etalon)
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.1
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-07 00:00:00.000000000 Z
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json