From 0f248e0b612d1b208ad19a1901e0689cc92cd9e8 Mon Sep 17 00:00:00 2001 From: Joe Stein Date: Fri, 3 Nov 2023 17:43:41 -0700 Subject: [PATCH] Add ActiveSupport::OrderedOptions inspection tree builder --- lib/super_diff/active_support.rb | 3 +- .../inspection_tree_builders.rb | 4 +++ .../ordered_options.rb | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb diff --git a/lib/super_diff/active_support.rb b/lib/super_diff/active_support.rb index e4f408f0..c907c1b2 100644 --- a/lib/super_diff/active_support.rb +++ b/lib/super_diff/active_support.rb @@ -18,7 +18,8 @@ module ActiveSupport OperationTreeBuilders::HashWithIndifferentAccess ) config.add_extra_inspection_tree_builder_classes( - ObjectInspection::InspectionTreeBuilders::HashWithIndifferentAccess + ObjectInspection::InspectionTreeBuilders::HashWithIndifferentAccess, + ObjectInspection::InspectionTreeBuilders::OrderedOptions ) end end diff --git a/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb b/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb index 05fc1625..412218e3 100644 --- a/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +++ b/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb @@ -6,6 +6,10 @@ module InspectionTreeBuilders :HashWithIndifferentAccess, "super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access" ) + autoload( + :OrderedOptions, + "super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options" + ) end end end diff --git a/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb b/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb new file mode 100644 index 00000000..97e2270a --- /dev/null +++ b/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb @@ -0,0 +1,33 @@ +module SuperDiff + module ActiveSupport + module ObjectInspection + module InspectionTreeBuilders + class OrderedOptions < SuperDiff::ObjectInspection::InspectionTreeBuilders::Hash + def self.applies_to?(value) + value.is_a?(::ActiveSupport::OrderedOptions) + end + + def call + SuperDiff::ObjectInspection::InspectionTree.new do + as_lines_when_rendering_to_lines(collection_bookend: :open) do + add_text "#" + end + end + end + end + end + end + end +end