hash_deep_diff 0.3.2 → 0.3.3

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: 184fe8aaacd6b6d10635f8ff8f0986381c8e2d907b14a80d86050aea75896136
4
- data.tar.gz: e4e33cc8c4ce40d84b0fbbe78fa380d1d62f65805f3ce5dc01e2049100db5b16
3
+ metadata.gz: fe3724394c10b36b7537f35bce5c7f079cae0ee3344062a78bdfe7256363624b
4
+ data.tar.gz: e9baa112b03013b91f75ebea9f243a0a6d51ca746ca8c8e66ea6fa38803198fd
5
5
  SHA512:
6
- metadata.gz: b299b5217a613175c47e5d56da723e0691cf7e2344abc9bbf9fab9525c96c776616971636365f0c2067f05ec8d22c205c98d896df4b1b17ee73f3541bb4e5736
7
- data.tar.gz: 159ffbeb7cdef03c130ed356f965379db05ebf8adec8b7e5186e1a45b4cbcc68489ce17b92a7e2bc38e58cdd2fafcb31c573703f566f348b0efdc0ef8c504d4e
6
+ metadata.gz: b7393bb437eddfb8e0ed66d4eba3b4135e221c7c2262df14aa4509dba98345c4766b598bd3c3f11f311c84b25b4f9f0b2bca3dfc5083c023c87c582fa607761a
7
+ data.tar.gz: 57708513050ac1e63c0ce64b9650e0ae0e3128127cbb4dfc5b248cc3caca3267cbd26bed7b939be4413c11f1a7038f5503aef143119a09e336cc113324ae182a
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # HashDeepDiff
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hash_deep_diff`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Find the exact difference between two Hash objects and build a report to visualize it
6
4
 
7
5
  ## Installation
8
6
 
@@ -21,15 +19,20 @@ Or install it yourself as:
21
19
  $ gem install hash_deep_diff
22
20
 
23
21
  ## Usage
22
+ Basic example
24
23
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+ ```ruby
25
+ left = { a: :a }
26
+ right = { a: :b }
30
27
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+ HashDeepDiff::Comparison.new(left, right).report
29
+ ```
30
+ ```diff
31
+ - left[a] = a
32
+ + right[a] = b
33
+ ```
32
34
 
33
35
  ## Contributing
34
36
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hash_deep_diff.
37
+ Bug reports and pull requests are welcome on GitHub at [bpohoriletz](https://github.com/bpohoriletz/hash_deep_diff).
38
+
@@ -23,6 +23,7 @@ module HashDeepDiff
23
23
  end
24
24
 
25
25
  # TOFIX poor naming
26
+ # overrides parameter in initializer
26
27
  def path
27
28
  @prefix + [@delta.keys.first]
28
29
  end
@@ -54,9 +55,11 @@ module HashDeepDiff
54
55
  # TOFIX this may prohibit usage of hashes with Array keys
55
56
  if path.respond_to?(:to_ary)
56
57
  @delta = { path[-1] => value }
58
+ @value = value
57
59
  @prefix = path[0..-2]
58
60
  else
59
61
  @delta = { path => value }
62
+ @value = value
60
63
  @prefix = []
61
64
  end
62
65
  end
@@ -11,29 +11,17 @@ module HashDeepDiff
11
11
  include Delta::ActsAsDelta
12
12
 
13
13
  def to_str
14
- if @delta.values.first.respond_to?(:to_hash)
15
- if @delta.values.first.keys == %i[left right]
16
- if complex?
17
- HashDeepDiff::Comparison.new(left, right, path).report
18
- else
19
- lines = <<~Q
20
- -left#{diff_prefix} = #{left}
21
- +right#{diff_prefix} = #{right}
22
- Q
23
- lines.strip
24
- end
25
- else
26
- @delta.values.first.keys.map do |key|
27
- self.class.new(path: path + [key], value: @delta.values.first[key])
28
- end.join("\n").strip
29
- end
30
- else
31
- lines = <<~Q
32
- -left#{diff_prefix} = #{left}
33
- +right#{diff_prefix} = #{right}
34
- Q
35
- lines.strip
36
- end
14
+ return diff unless complex?
15
+
16
+ HashDeepDiff::Comparison.new(left, right, path).report
17
+ end
18
+
19
+ def diff
20
+ lines = <<~Q
21
+ -left#{diff_prefix} = #{left}
22
+ +right#{diff_prefix} = #{right}
23
+ Q
24
+ lines.strip
37
25
  end
38
26
 
39
27
  def complex?
@@ -41,11 +29,11 @@ module HashDeepDiff
41
29
  end
42
30
 
43
31
  def left
44
- @delta.values.first[:left]
32
+ @value[:left]
45
33
  end
46
34
 
47
35
  def right
48
- @delta.values.first[:right]
36
+ @value[:right]
49
37
  end
50
38
  end
51
39
  end
@@ -11,13 +11,19 @@ module HashDeepDiff
11
11
  include Delta::ActsAsDelta
12
12
 
13
13
  def to_str
14
- if @delta.values.first.respond_to?(:to_hash)
15
- @delta.values.first.keys.map do |key|
16
- self.class.new(path: path + [key], value: @delta.values.first[key])
17
- end.join("\n").strip
18
- else
19
- "+left#{diff_prefix} = #{@delta.values.first}"
20
- end
14
+ return "+left#{diff_prefix} = #{left}" unless left.respond_to?(:to_hash)
15
+
16
+ left.keys.map do |key|
17
+ self.class.new(path: path + [key], value: left[key])
18
+ end.join("\n").strip
19
+ end
20
+
21
+ def left
22
+ @value
23
+ end
24
+
25
+ def right
26
+ nil
21
27
  end
22
28
  end
23
29
  end
@@ -11,13 +11,19 @@ module HashDeepDiff
11
11
  include Delta::ActsAsDelta
12
12
 
13
13
  def to_str
14
- if @delta.values.first.respond_to?(:to_hash)
15
- @delta.values.first.keys.map do |key|
16
- self.class.new(path: path + [key], value: @delta.values.first[key])
17
- end.join("\n").strip
18
- else
19
- "-left#{diff_prefix} = #{@delta.values.first}"
20
- end
14
+ return "-left#{diff_prefix} = #{right}" unless right.respond_to?(:to_hash)
15
+
16
+ right.keys.map do |key|
17
+ self.class.new(path: path + [key], value: right[key])
18
+ end.join("\n").strip
19
+ end
20
+
21
+ def left
22
+ nil
23
+ end
24
+
25
+ def right
26
+ @value
21
27
  end
22
28
  end
23
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HashDeepDiff
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_deep_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bohdan Pohorilets
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-12 00:00:00.000000000 Z
11
+ date: 2022-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler