super_diff 0.12.1 → 0.13.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: b261fa1a942123632f87e74d6b123826571840e9d779d21424ca590b6a646f8f
4
- data.tar.gz: a2a780bc9752ec935edfd34bfb7588aa13c8a2357f1422037102e1c7774c31db
3
+ metadata.gz: 343438b938b014502f7af0df76fc22ff73f3eaada655081b994b8c4d77bd3618
4
+ data.tar.gz: 2738da41f517ecfcd1e068e03256cd37aa5436fd984856a2c958518596bd58bf
5
5
  SHA512:
6
- metadata.gz: 45a49cec47615c6c82e1cbae577c1bd9ad57852469f7a69d13c7daa8425971f8fdb109de7991db7b3f810dfcd9eb58d0cd1635c9497b913496ef8e5ab9e0f73b
7
- data.tar.gz: 8bf439969e3e15fe39661e25e65abca5a442a055efad43089d16bdd0a383c36c0ff02c67a6f73644d04c5581c8cf2a0c72b50f5a67d543046acd875a8c081e64
6
+ metadata.gz: 522481e293667b16bf0d2c752fc02ebce5c6b8c607d23d53b009d52eec34e9a0d429fa410cb8dc4802c5b9b3dffd20632f9671024e3ba009e591179a6cb155dc
7
+ data.tar.gz: c08edc9460956e59f391249f26b508c944797ceda4db80d36b2119415322ef00210cd57817e74f24b6d13cc3b869bf7de1ca50276cd75e01288b1733c4c48b43
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
- # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][gh-actions-badge]][gh-actions] ![Downloads][downloads-badge] [![IssueHunt][issuehunt-badge]][issuehunt]
1
+ # SuperDiff [![Gem Version][version-badge]][rubygems] [![Build Status][gh-actions-badge]][gh-actions] ![Downloads][downloads-badge]
2
2
 
3
3
  [version-badge]: http://img.shields.io/gem/v/super_diff.svg
4
4
  [rubygems]: http://rubygems.org/gems/super_diff
5
- [gh-actions-badge]: https://img.shields.io/github/actions/workflow/status/mcmire/super_diff/super_diff.yml?branch=master
5
+ [gh-actions-badge]: https://img.shields.io/github/actions/workflow/status/splitwise/super_diff/super_diff.yml?branch=main
6
6
  [downloads-badge]: http://img.shields.io/gem/dtv/super_diff.svg
7
7
  [hound]: https://houndci.com
8
- [issuehunt-badge]: https://img.shields.io/badge/sponsored_through-IssueHunt-2EC28C
9
- [issuehunt]: https://issuehunt.io/r/mcmire/super_diff
10
8
 
11
9
  **SuperDiff** is a Ruby gem
12
10
  which is designed to display the differences between two objects of any type
@@ -102,7 +100,7 @@ and you encounter a bug or have a suggestion,
102
100
  feel free to [create an issue][issues-list].
103
101
  I'll try to respond to it as soon as I can!
104
102
 
105
- [issues-list]: https://github.com/mcmire/super_diff/issues
103
+ [issues-list]: https://github.com/splitwise/super_diff/issues
106
104
 
107
105
  ## Contributing
108
106
 
@@ -110,16 +108,6 @@ Any code contributions to improve this library are welcome!
110
108
  Please see the [contributing](./docs/contributors/index.md) document
111
109
  for more on how to do that.
112
110
 
113
- ## Sponsoring
114
-
115
- If there's a change you want implemented, you can choose to sponsor that change!
116
- `super_diff` is set up on IssueHunt,
117
- so feel free to search for an existing issue (or make your own)
118
- and [add a bounty][issuehunt].
119
- I'll get notified right away!
120
-
121
- [issuehunt]: https://issuehunt.io/r/mcmire/super_diff
122
-
123
111
  ## Compatibility
124
112
 
125
113
  `super_diff` is [tested][gh-actions] to work with
@@ -127,7 +115,7 @@ Ruby >= 3.x,
127
115
  RSpec 3.x,
128
116
  and Rails >= 6.x.
129
117
 
130
- [gh-actions]: https://github.com/mcmire/super_diff/actions?query=workflow%3ASuperDiff
118
+ [gh-actions]: https://github.com/splitwise/super_diff/actions?query=workflow%3ASuperDiff
131
119
 
132
120
  ## Inspiration/Thanks
133
121
 
@@ -142,13 +130,13 @@ I made use of or was heavily inspired by these libraries:
142
130
 
143
131
  Thank you to the authors of these libraries!
144
132
 
145
- [original-version]: https://github.com/mcmire/super_diff/tree/old-master
133
+ [original-version]: https://github.com/splitwise/super_diff/tree/old-master
146
134
  [diff-lcs]: https://github.com/halostatue/diff-lcs
147
135
  [pretty-printer]: https://github.com/ruby/ruby/tree/master/lib/prettyprint.rb
148
136
  [awesome-print]: https://github.com/awesome-print/awesome_print
149
- [inspection-tree]: https://github.com/mcmire/super_diff/blob/master/lib/super_diff/object_inspection/inspection_tree.rb
137
+ [inspection-tree]: https://github.com/splitwise/super_diff/blob/main/lib/super_diff/object_inspection/inspection_tree.rb
150
138
 
151
139
  ## Author/License
152
140
 
153
- SuperDiff was created and is maintained by Elliot Winkler.
141
+ SuperDiff was created by Elliot Winkler and is maintained by Splitwise, Inc.
154
142
  It is released under the [MIT license](LICENSE).
@@ -0,0 +1,40 @@
1
+ module SuperDiff
2
+ module Basic
3
+ module InspectionTreeBuilders
4
+ class DataObject < Core::AbstractInspectionTreeBuilder
5
+ def self.applies_to?(value)
6
+ SuperDiff::Core::Helpers.ruby_version_matches?("~> 3.2") &&
7
+ value.is_a?(Data)
8
+ end
9
+
10
+ def call
11
+ Core::InspectionTree.new do |t1|
12
+ t1.as_lines_when_rendering_to_lines(
13
+ collection_bookend: :open
14
+ ) do |t2|
15
+ t2.add_text "#<data #{object.class.name} "
16
+
17
+ # stree-ignore
18
+ t2.when_rendering_to_lines do |t3|
19
+ t3.add_text "{"
20
+ end
21
+ end
22
+
23
+ t1.nested { |t2| t2.insert_hash_inspection_of(object.to_h) }
24
+
25
+ t1.as_lines_when_rendering_to_lines(
26
+ collection_bookend: :close
27
+ ) do |t2|
28
+ # stree-ignore
29
+ t2.when_rendering_to_lines do |t3|
30
+ t3.add_text "}"
31
+ end
32
+
33
+ t2.add_text ">"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -3,7 +3,7 @@ module SuperDiff
3
3
  module InspectionTreeBuilders
4
4
  class Primitive < Core::AbstractInspectionTreeBuilder
5
5
  def self.applies_to?(value)
6
- SuperDiff.primitive?(value) || value.is_a?(::String)
6
+ SuperDiff.primitive?(value)
7
7
  end
8
8
 
9
9
  def call
@@ -6,6 +6,10 @@ module SuperDiff
6
6
  :CustomObject,
7
7
  "super_diff/basic/inspection_tree_builders/custom_object"
8
8
  )
9
+ autoload(
10
+ :DataObject,
11
+ "super_diff/basic/inspection_tree_builders/data_object"
12
+ )
9
13
  autoload(
10
14
  :DefaultObject,
11
15
  "super_diff/basic/inspection_tree_builders/default_object"
@@ -0,0 +1,18 @@
1
+ module SuperDiff
2
+ module Basic
3
+ module OperationTreeBuilders
4
+ class DataObject < CustomObject
5
+ def self.applies_to?(expected, actual)
6
+ SuperDiff::Core::Helpers.ruby_version_matches?("~> 3.2") &&
7
+ expected.class == actual.class && expected.is_a?(Data)
8
+ end
9
+
10
+ protected
11
+
12
+ def attribute_names
13
+ expected.members & actual.members
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -6,6 +6,10 @@ module SuperDiff
6
6
  :CustomObject,
7
7
  "super_diff/basic/operation_tree_builders/custom_object"
8
8
  )
9
+ autoload(
10
+ :DataObject,
11
+ "super_diff/basic/operation_tree_builders/data_object"
12
+ )
9
13
  autoload(
10
14
  :DefaultObject,
11
15
  "super_diff/basic/operation_tree_builders/default_object"
@@ -26,6 +26,7 @@ module SuperDiff
26
26
  InspectionTreeBuilders::Primitive,
27
27
  InspectionTreeBuilders::TimeLike,
28
28
  InspectionTreeBuilders::DateLike,
29
+ InspectionTreeBuilders::DataObject,
29
30
  InspectionTreeBuilders::DefaultObject
30
31
  )
31
32
 
@@ -34,7 +35,8 @@ module SuperDiff
34
35
  OperationTreeBuilders::Hash,
35
36
  OperationTreeBuilders::TimeLike,
36
37
  OperationTreeBuilders::DateLike,
37
- OperationTreeBuilders::CustomObject
38
+ OperationTreeBuilders::CustomObject,
39
+ OperationTreeBuilders::DataObject
38
40
  )
39
41
 
40
42
  config.add_extra_operation_tree_classes(
@@ -23,7 +23,7 @@ module SuperDiff
23
23
  def initialize(options = {})
24
24
  @actual_color = :yellow
25
25
  @border_color = :blue
26
- @color_enabled = color_enabled_by_default?
26
+ @color_enabled = nil
27
27
  @diff_elision_enabled = false
28
28
  @diff_elision_maximum = 0
29
29
  @elision_marker_color = :cyan
@@ -41,6 +41,8 @@ module SuperDiff
41
41
 
42
42
  def initialize_dup(original)
43
43
  super
44
+ @extra_diff_formatter_classes =
45
+ original.extra_diff_formatter_classes.dup.freeze
44
46
  @extra_differ_classes = original.extra_differ_classes.dup.freeze
45
47
  @extra_operation_tree_builder_classes =
46
48
  original.extra_operation_tree_builder_classes.dup.freeze
@@ -51,6 +53,8 @@ module SuperDiff
51
53
  end
52
54
 
53
55
  def color_enabled?
56
+ return color_enabled_by_default? if @color_enabled.nil?
57
+
54
58
  @color_enabled
55
59
  end
56
60
 
@@ -71,12 +75,6 @@ module SuperDiff
71
75
  end
72
76
 
73
77
  options.each { |key, value| instance_variable_set("@#{key}", value) }
74
-
75
- updated
76
- end
77
-
78
- def updated
79
- SuperDiff::Csi.color_enabled = color_enabled?
80
78
  end
81
79
 
82
80
  def add_extra_diff_formatter_classes(*classes)
@@ -165,7 +163,7 @@ module SuperDiff
165
163
  {
166
164
  actual_color: actual_color,
167
165
  border_color: border_color,
168
- color_enabled: color_enabled?,
166
+ color_enabled: @color_enabled,
169
167
  diff_elision_enabled: diff_elision_enabled?,
170
168
  diff_elision_maximum: diff_elision_maximum,
171
169
  elision_marker_color: elision_marker_color,
@@ -185,7 +183,13 @@ module SuperDiff
185
183
  private
186
184
 
187
185
  def color_enabled_by_default?
188
- ENV["CI"] == "true" || $stdout.respond_to?(:tty?) && $stdout.tty?
186
+ return true if ENV["CI"] == "true"
187
+
188
+ if defined?(::SuperDiff::RSpec)
189
+ return ::RSpec.configuration.color_enabled?
190
+ end
191
+
192
+ $stdout.respond_to?(:tty?) && $stdout.tty?
189
193
  end
190
194
  end
191
195
  end
@@ -6,7 +6,7 @@ module SuperDiff
6
6
  # TODO: Simplify this
7
7
  def style(*args, color_enabled: true, **opts, &block)
8
8
  klass =
9
- if color_enabled && Csi.color_enabled?
9
+ if color_enabled && SuperDiff.configuration.color_enabled?
10
10
  Csi::ColorizedDocument
11
11
  else
12
12
  Csi::UncolorizedDocument
@@ -12,26 +12,10 @@ module SuperDiff
12
12
  autoload :TwentyFourBitColor, "super_diff/csi/twenty_four_bit_color"
13
13
  autoload :UncolorizedDocument, "super_diff/csi/uncolorized_document"
14
14
 
15
- class << self
16
- attr_writer :color_enabled
17
- end
18
-
19
15
  def self.reset_sequence
20
16
  ResetSequence.new
21
17
  end
22
18
 
23
- def self.color_enabled?
24
- @color_enabled
25
- end
26
-
27
- def self.colorize(*args, **opts, &block)
28
- if color_enabled?
29
- ColorizedDocument.new(*args, **opts, &block)
30
- else
31
- UncolorizedDocument.new(*args, **opts, &block)
32
- end
33
- end
34
-
35
19
  def self.decolorize(text)
36
20
  text.gsub(/\e\[\d+(?:;\d+)*m(.+?)\e\[0m/, '\1')
37
21
  end
@@ -39,21 +23,5 @@ module SuperDiff
39
23
  def self.already_colorized?(text)
40
24
  text.match?(/\e\[\d+m/)
41
25
  end
42
-
43
- def self.inspect_colors_in(text)
44
- [FourBitColor, EightBitColor, TwentyFourBitColor].reduce(
45
- text
46
- ) do |str, klass|
47
- klass.sub_colorized_areas_in(str) do |area, color|
48
- color_block = colorize("◼︎", color.to_foreground)
49
-
50
- layer_indicator = (color.foreground? ? "(fg)" : "(bg)")
51
-
52
- "#{color_block} #{layer_indicator} ❮#{area}❯"
53
- end
54
- end
55
- end
56
-
57
- self.color_enabled = false
58
26
  end
59
27
  end
@@ -1,11 +1,11 @@
1
1
  module SuperDiff
2
2
  module EqualityMatchers
3
3
  DEFAULTS = [
4
- Primitive,
5
4
  Array,
6
5
  Hash,
7
6
  MultilineString,
8
7
  SinglelineString,
8
+ Primitive,
9
9
  Default
10
10
  ].freeze
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module SuperDiff
2
- VERSION = "0.12.1".freeze
2
+ VERSION = "0.13.0".freeze
3
3
  end
data/lib/super_diff.rb CHANGED
@@ -36,7 +36,6 @@ module SuperDiff
36
36
 
37
37
  def self.configure
38
38
  yield configuration
39
- configuration.updated
40
39
  end
41
40
 
42
41
  def self.configuration
@@ -114,7 +113,7 @@ module SuperDiff
114
113
 
115
114
  def self.primitive?(value)
116
115
  case value
117
- when true, false, nil, Symbol, Numeric, Regexp, Class
116
+ when true, false, nil, Symbol, Numeric, Regexp, Class, String
118
117
  true
119
118
  else
120
119
  false