Skip to content

Commit

Permalink
Add ActiveSupport::OrderedOptions inspection tree builder
Browse files Browse the repository at this point in the history
  • Loading branch information
jas14 committed Nov 4, 2023
1 parent 26e1f6c commit 0f248e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/super_diff/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 "#<OrderedOptions {"
end

when_rendering_to_string { add_text " " }

nested do |ordered_options|
insert_hash_inspection_of(ordered_options.to_hash)
end

when_rendering_to_string { add_text " " }

as_lines_when_rendering_to_lines(collection_bookend: :close) do
add_text "}>"
end
end
end
end
end
end
end
end

0 comments on commit 0f248e0

Please sign in to comment.