Module: SuperDiff

Defined in:
lib/super_diff/csi.rb,
lib/super_diff.rb,
lib/super_diff/core.rb,
lib/super_diff/basic.rb,
lib/super_diff/rspec.rb,
lib/super_diff/errors.rb,
lib/super_diff/differs.rb,
lib/super_diff/version.rb,
lib/super_diff/core/line.rb,
lib/super_diff/csi/color.rb,
lib/super_diff/operations.rb,
lib/super_diff/core/helpers.rb,
lib/super_diff/csi/document.rb,
lib/super_diff/rspec/differ.rb,
lib/super_diff/active_record.rb,
lib/super_diff/basic/differs.rb,
lib/super_diff/rspec/differs.rb,
lib/super_diff/active_support.rb,
lib/super_diff/operation_trees.rb,
lib/super_diff/core/gem_version.rb,
lib/super_diff/core/tiered_lines.rb,
lib/super_diff/csi/bold_sequence.rb,
lib/super_diff/equality_matchers.rb,
lib/super_diff/object_inspection.rb,
lib/super_diff/basic/differs/hash.rb,
lib/super_diff/core/configuration.rb,
lib/super_diff/csi/four_bit_color.rb,
lib/super_diff/csi/reset_sequence.rb,
lib/super_diff/basic/differs/array.rb,
lib/super_diff/csi/eight_bit_color.rb,
lib/super_diff/core/abstract_differ.rb,
lib/super_diff/core/inspection_tree.rb,
lib/super_diff/core/recursion_guard.rb,
lib/super_diff/core/unary_operation.rb,
lib/super_diff/active_record/differs.rb,
lib/super_diff/basic/diff_formatters.rb,
lib/super_diff/basic/operation_trees.rb,
lib/super_diff/core/binary_operation.rb,
lib/super_diff/active_support/differs.rb,
lib/super_diff/core/differ_dispatcher.rb,
lib/super_diff/csi/colorized_document.rb,
lib/super_diff/equality_matchers/base.rb,
lib/super_diff/equality_matchers/hash.rb,
lib/super_diff/equality_matchers/main.rb,
lib/super_diff/basic/differs/date_like.rb,
lib/super_diff/basic/differs/time_like.rb,
lib/super_diff/equality_matchers/array.rb,
lib/super_diff/operation_tree_builders.rb,
lib/super_diff/rspec/augmented_matcher.rb,
lib/super_diff/rspec/object_inspection.rb,
lib/super_diff/core/tiered_lines_elider.rb,
lib/super_diff/csi/color_sequence_block.rb,
lib/super_diff/csi/uncolorized_document.rb,
lib/super_diff/csi/twenty_four_bit_color.rb,
lib/super_diff/equality_matchers/default.rb,
lib/super_diff/operation_tree_flatteners.rb,
lib/super_diff/basic/operation_trees/hash.rb,
lib/super_diff/core/implementation_checks.rb,
lib/super_diff/core/inspection_tree_nodes.rb,
lib/super_diff/core/operation_tree_finder.rb,
lib/super_diff/equality_matchers/defaults.rb,
lib/super_diff/basic/differs/custom_object.rb,
lib/super_diff/basic/operation_trees/array.rb,
lib/super_diff/core/tiered_lines_formatter.rb,
lib/super_diff/equality_matchers/primitive.rb,
lib/super_diff/rspec/matcher_text_builders.rb,
lib/super_diff/rspec/matcher_text_template.rb,
lib/super_diff/basic/differs/default_object.rb,
lib/super_diff/core/abstract_operation_tree.rb,
lib/super_diff/rspec/differs/hash_including.rb,
lib/super_diff/active_record/operation_trees.rb,
lib/super_diff/basic/operation_tree_builders.rb,
lib/super_diff/rspec/operation_tree_builders.rb,
lib/super_diff/active_support/operation_trees.rb,
lib/super_diff/basic/differs/multiline_string.rb,
lib/super_diff/basic/inspection_tree_builders.rb,
lib/super_diff/core/no_differ_available_error.rb,
lib/super_diff/rspec/inspection_tree_builders.rb,
lib/super_diff/active_record/object_inspection.rb,
lib/super_diff/basic/operation_tree_flatteners.rb,
lib/super_diff/core/inspection_tree_nodes/base.rb,
lib/super_diff/core/inspection_tree_nodes/text.rb,
lib/super_diff/active_support/object_inspection.rb,
lib/super_diff/basic/diff_formatters/collection.rb,
lib/super_diff/rspec/matcher_text_builders/base.rb,
lib/super_diff/rspec/matcher_text_builders/match.rb,
lib/super_diff/basic/operation_tree_builders/hash.rb,
lib/super_diff/core/colorized_document_extensions.rb,
lib/super_diff/core/inspection_tree_nodes/nesting.rb,
lib/super_diff/equality_matchers/multiline_string.rb,
lib/super_diff/rspec/differs/collection_including.rb,
lib/super_diff/basic/inspection_tree_builders/hash.rb,
lib/super_diff/basic/operation_tree_builders/array.rb,
lib/super_diff/basic/operation_trees/custom_object.rb,
lib/super_diff/equality_matchers/singleline_string.rb,
lib/super_diff/basic/inspection_tree_builders/array.rb,
lib/super_diff/basic/operation_tree_flatteners/hash.rb,
lib/super_diff/basic/operation_trees/default_object.rb,
lib/super_diff/core/abstract_operation_tree_builder.rb,
lib/super_diff/core/inspection_tree_nodes/only_when.rb,
lib/super_diff/active_record/operation_tree_builders.rb,
lib/super_diff/basic/operation_tree_flatteners/array.rb,
lib/super_diff/core/abstract_inspection_tree_builder.rb,
lib/super_diff/core/inspection_tree_nodes/inspection.rb,
lib/super_diff/core/inspection_tree_nodes/when_empty.rb,
lib/super_diff/rspec/inspection_tree_builders/double.rb,
lib/super_diff/active_record/inspection_tree_builders.rb,
lib/super_diff/active_support/operation_tree_builders.rb,
lib/super_diff/basic/diff_formatters/multiline_string.rb,
lib/super_diff/basic/operation_trees/multiline_string.rb,
lib/super_diff/core/abstract_operation_tree_flattener.rb,
lib/super_diff/core/no_operation_tree_available_error.rb,
lib/super_diff/core/operation_tree_builder_dispatcher.rb,
lib/super_diff/rspec/differs/object_having_attributes.rb,
lib/super_diff/rspec/inspection_tree_builders/kind_of.rb,
lib/super_diff/rspec/matcher_text_builders/respond_to.rb,
lib/super_diff/active_record/operation_tree_flatteners.rb,
lib/super_diff/active_support/inspection_tree_builders.rb,
lib/super_diff/basic/operation_tree_builders/date_like.rb,
lib/super_diff/basic/operation_tree_builders/time_like.rb,
lib/super_diff/core/inspection_tree_builder_dispatcher.rb,
lib/super_diff/rspec/matcher_text_builders/raise_error.rb,
lib/super_diff/active_support/operation_tree_flatteners.rb,
lib/super_diff/basic/inspection_tree_builders/date_like.rb,
lib/super_diff/basic/inspection_tree_builders/primitive.rb,
lib/super_diff/basic/inspection_tree_builders/time_like.rb,
lib/super_diff/rspec/inspection_tree_builders/primitive.rb,
lib/super_diff/rspec/matcher_text_builders/be_predicate.rb,
lib/super_diff/basic/operation_tree_builders/data_object.rb,
lib/super_diff/core/inspection_tree_nodes/as_single_line.rb,
lib/super_diff/core/inspection_tree_nodes/when_non_empty.rb,
lib/super_diff/core/prefix_for_next_inspection_tree_node.rb,
lib/super_diff/basic/inspection_tree_builders/data_object.rb,
lib/super_diff/basic/operation_tree_flatteners/collection.rb,
lib/super_diff/core/prelude_for_next_inspection_tree_node.rb,
lib/super_diff/rspec/inspection_tree_builders/instance_of.rb,
lib/super_diff/rspec/matcher_text_builders/have_predicate.rb,
lib/super_diff/basic/inspection_tree_builders/range_object.rb,
lib/super_diff/basic/operation_tree_builders/custom_object.rb,
lib/super_diff/rspec/differs/collection_containing_exactly.rb,
lib/super_diff/rspec/inspection_tree_builders/value_within.rb,
lib/super_diff/rspec/matcher_text_builders/contain_exactly.rb,
lib/super_diff/active_record/differs/active_record_relation.rb,
lib/super_diff/basic/inspection_tree_builders/custom_object.rb,
lib/super_diff/basic/operation_tree_builders/default_object.rb,
lib/super_diff/rspec/operation_tree_builders/hash_including.rb,
lib/super_diff/basic/inspection_tree_builders/default_object.rb,
lib/super_diff/basic/operation_tree_flatteners/custom_object.rb,
lib/super_diff/rspec/inspection_tree_builders/hash_including.rb,
lib/super_diff/basic/operation_tree_builders/multiline_string.rb,
lib/super_diff/basic/operation_tree_flatteners/default_object.rb,
lib/super_diff/core/no_operation_tree_builder_available_error.rb,
lib/super_diff/core/no_inspection_tree_builder_available_error.rb,
lib/super_diff/basic/operation_tree_flatteners/multiline_string.rb,
lib/super_diff/core/inspection_tree_nodes/when_rendering_to_lines.rb,
lib/super_diff/rspec/operation_tree_builders/collection_including.rb,
lib/super_diff/active_support/differs/hash_with_indifferent_access.rb,
lib/super_diff/core/inspection_tree_nodes/when_rendering_to_string.rb,
lib/super_diff/rspec/inspection_tree_builders/collection_including.rb,
lib/super_diff/active_record/operation_trees/active_record_relation.rb,
lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb,
lib/super_diff/active_support/inspection_tree_builders/ordered_options.rb,
lib/super_diff/rspec/inspection_tree_builders/object_having_attributes.rb,
lib/super_diff/active_record/operation_tree_builders/active_record_model.rb,
lib/super_diff/active_record/inspection_tree_builders/active_record_model.rb,
lib/super_diff/rspec/inspection_tree_builders/generic_describable_matcher.rb,
lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb,
lib/super_diff/core/inspection_tree_nodes/as_lines_when_rendering_to_lines.rb,
lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb,
lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb,
lib/super_diff/core/inspection_tree_nodes/as_prefix_when_rendering_to_lines.rb,
lib/super_diff/rspec/inspection_tree_builders/collection_containing_exactly.rb,
lib/super_diff/active_record/inspection_tree_builders/active_record_relation.rb,
lib/super_diff/core/inspection_tree_nodes/as_prelude_when_rendering_to_lines.rb,
lib/super_diff/active_record/operation_tree_flatteners/active_record_relation.rb,
lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb,
lib/super_diff/active_support/inspection_tree_builders/hash_with_indifferent_access.rb,
lib/super_diff/active_support/operation_tree_flatteners/hash_with_indifferent_access.rb

Overview

Defined Under Namespace

Modules: ActiveRecord, ActiveSupport, Basic, Core, Csi, Differs, EqualityMatchers, Errors, ObjectInspection, OperationTreeBuilders, OperationTreeFlatteners, OperationTrees, Operations, RSpec

Constant Summary collapse

VERSION =
'0.14.0'

Class Method Summary collapse

Class Method Details

.build_operation_tree_for(expected, actual, extra_operation_tree_builder_classes: [], raise_if_nothing_applies: false) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/super_diff.rb', line 62

def self.build_operation_tree_for(
  expected,
  actual,
  extra_operation_tree_builder_classes: [],
  raise_if_nothing_applies: false
)
  Core::OperationTreeBuilderDispatcher.call(
    expected,
    actual,
    available_classes:
      configuration.extra_operation_tree_builder_classes +
        extra_operation_tree_builder_classes,
    raise_if_nothing_applies: raise_if_nothing_applies
  )
end

.configurationObject



43
44
45
# File 'lib/super_diff.rb', line 43

def self.configuration
  @configuration ||= Core::Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



39
40
41
# File 'lib/super_diff.rb', line 39

def self.configure
  yield configuration
end

.const_missing(missing_const_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/super_diff.rb', line 19

def self.const_missing(missing_const_name)
  if Core.const_defined?(missing_const_name)
    warn <<~WARNING
      WARNING: SuperDiff::#{missing_const_name} is deprecated and will be removed in the next major release.
      Please use SuperDiff::Core::#{missing_const_name} instead.
      #{caller_locations.join("\n")}
    WARNING
    Core.const_get(missing_const_name)
  elsif Basic.const_defined?(missing_const_name)
    warn <<~WARNING
      WARNING: SuperDiff::#{missing_const_name} is deprecated and will be removed in the next major release.
      Please use SuperDiff::Basic::#{missing_const_name} instead.
      #{caller_locations.join("\n")}
    WARNING
    Basic.const_get(missing_const_name)
  else
    super
  end
end

.date_like?(value) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
112
113
114
# File 'lib/super_diff.rb', line 108

def self.date_like?(value)
  # Check for ActiveSupport's #acts_like_date? for their date-like objects
  # In case class is both time-like and date-like, we should treat it as
  # time-like. This is governed by the order of `Differs::DEFAULTS` entries
  (value.respond_to?(:acts_like_date?) && value.acts_like_date?) ||
    value.is_a?(Date)
end

.diff(expected, actual, indent_level: 0, raise_if_nothing_applies: true) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/super_diff.rb', line 47

def self.diff(
  expected,
  actual,
  indent_level: 0,
  raise_if_nothing_applies: true
)
  Core::DifferDispatcher.call(
    expected,
    actual,
    available_classes: configuration.extra_differ_classes,
    indent_level: indent_level,
    raise_if_nothing_applies: raise_if_nothing_applies
  )
end

.find_operation_tree_for(value) ⇒ Object



78
79
80
81
82
83
# File 'lib/super_diff.rb', line 78

def self.find_operation_tree_for(value)
  SuperDiff::Core::OperationTreeFinder.call(
    value,
    available_classes: configuration.extra_operation_tree_classes
  )
end

.insert_overrides(target_module, mod = nil, &block) ⇒ Object



125
126
127
# File 'lib/super_diff.rb', line 125

def self.insert_overrides(target_module, mod = nil, &block)
  target_module.prepend(mod || Module.new(&block))
end

.insert_singleton_overrides(target_module, mod = nil, &block) ⇒ Object



129
130
131
# File 'lib/super_diff.rb', line 129

def self.insert_singleton_overrides(target_module, mod = nil, &block)
  target_module.singleton_class.prepend(mod || Module.new(&block))
end

.inspect_object(object, as_lines:, **rest) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/super_diff.rb', line 85

def self.inspect_object(object, as_lines:, **rest)
  Core::RecursionGuard.guarding_recursion_of(object) do
    inspection_tree =
      Core::InspectionTreeBuilderDispatcher.call(
        object,
        available_classes: configuration.extra_inspection_tree_builder_classes
      )

    if as_lines
      inspection_tree.render_to_lines(object, **rest)
    else
      inspection_tree.render_to_string(object)
    end
  end
end

.primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
# File 'lib/super_diff.rb', line 116

def self.primitive?(value)
  case value
  when true, false, nil, Symbol, Numeric, Regexp, Class, Module, String
    true
  else
    false
  end
end

.time_like?(value) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
# File 'lib/super_diff.rb', line 101

def self.time_like?(value)
  # Check for ActiveSupport's #acts_like_time? for their time-like objects
  # (like ActiveSupport::TimeWithZone).
  (value.respond_to?(:acts_like_time?) && value.acts_like_time?) ||
    value.is_a?(Time)
end