From 0f23b59979a1f3c6ed2dcd82797ca20b2396b589 Mon Sep 17 00:00:00 2001 From: Paul DobbinSchmaltz Date: Fri, 15 Nov 2024 12:15:58 -0600 Subject: [PATCH] Insert an interface layer for object_inspector gem use Add ObjectInspectionBehaviors -- an interface layer to the inspection helper in the object_inspector gem. Using this approach, we are able to e.g. conditionally enable object_inspector throughout the entire app. --- app/models/board.rb | 2 +- app/models/board/settings.rb | 2 +- app/models/calc_3bv.rb | 6 +++--- app/models/cell.rb | 2 +- app/models/game.rb | 2 +- app/models/grid.rb | 2 +- app/models/pattern.rb | 2 +- app/models/pattern/settings.rb | 2 +- app/models/transactions/cell_transaction.rb | 2 +- app/models/transactions/game_transaction.rb | 2 +- app/models/transactions/user_update_transaction.rb | 2 +- app/models/user.rb | 2 +- lib/object_inspection_behaviors.rb | 10 ++++++++++ 13 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 lib/object_inspection_behaviors.rb diff --git a/app/models/board.rb b/app/models/board.rb index b55ceeb..ddce7ae 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -94,7 +94,7 @@ def validate_settings end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify diff --git a/app/models/board/settings.rb b/app/models/board/settings.rb index 75e5532..5f8d3f0 100644 --- a/app/models/board/settings.rb +++ b/app/models/board/settings.rb @@ -117,7 +117,7 @@ def as_json = to_h def to_a = to_h.values concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify(:width, :height, :mines) diff --git a/app/models/calc_3bv.rb b/app/models/calc_3bv.rb index 9f08bb5..67bca91 100644 --- a/app/models/calc_3bv.rb +++ b/app/models/calc_3bv.rb @@ -43,7 +43,7 @@ def process_cells def count = cells.sum(&:count) concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify(:grid) end @@ -103,7 +103,7 @@ def neighbors = calculator.cells_at(neighboring_coordinates) def neighboring_coordinates = coordinates.neighbors concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_flags(scope:) scope.join_flags([ @@ -146,7 +146,7 @@ def render def grid = super.console concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify(:grid, klass: __class__) end diff --git a/app/models/cell.rb b/app/models/cell.rb index 5e77699..11ef9f5 100644 --- a/app/models/cell.rb +++ b/app/models/cell.rb @@ -143,7 +143,7 @@ def neighboring_flags_count end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify diff --git a/app/models/game.rb b/app/models/game.rb index 56c0c65..8edbf27 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -192,7 +192,7 @@ def set_stats end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify diff --git a/app/models/grid.rb b/app/models/grid.rb index 2fd2607..781da1c 100644 --- a/app/models/grid.rb +++ b/app/models/grid.rb @@ -60,7 +60,7 @@ def organizer end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = self.class.name diff --git a/app/models/pattern.rb b/app/models/pattern.rb index 6744c4c..b835c97 100644 --- a/app/models/pattern.rb +++ b/app/models/pattern.rb @@ -78,7 +78,7 @@ def validate_settings end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify diff --git a/app/models/pattern/settings.rb b/app/models/pattern/settings.rb index 3f714c3..c451d10 100644 --- a/app/models/pattern/settings.rb +++ b/app/models/pattern/settings.rb @@ -42,7 +42,7 @@ def to_a = to_h.values def as_json = to_h concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify(:width, :height) end diff --git a/app/models/transactions/cell_transaction.rb b/app/models/transactions/cell_transaction.rb index 81b1bd7..9ed6f24 100644 --- a/app/models/transactions/cell_transaction.rb +++ b/app/models/transactions/cell_transaction.rb @@ -40,7 +40,7 @@ def self.exists_between?(user:, cell:) end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify diff --git a/app/models/transactions/game_transaction.rb b/app/models/transactions/game_transaction.rb index 87f610e..dd5bf13 100644 --- a/app/models/transactions/game_transaction.rb +++ b/app/models/transactions/game_transaction.rb @@ -33,7 +33,7 @@ def self.exists_between?(user:, game:) end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify diff --git a/app/models/transactions/user_update_transaction.rb b/app/models/transactions/user_update_transaction.rb index 42f94b8..274228b 100644 --- a/app/models/transactions/user_update_transaction.rb +++ b/app/models/transactions/user_update_transaction.rb @@ -22,7 +22,7 @@ def self.create_for(user:, change_set:) end concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify diff --git a/app/models/user.rb b/app/models/user.rb index 9d999aa..fe85d37 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -73,7 +73,7 @@ def completed_games_count def bests = @bests ||= Bests.new(self) concerning :ObjectInspection do - include ObjectInspector::InspectorsHelper + include ObjectInspectionBehaviors def inspect_identification = identify(:truncated_id) def truncated_id = id[TRUNCATED_ID_RANGE] diff --git a/lib/object_inspection_behaviors.rb b/lib/object_inspection_behaviors.rb new file mode 100644 index 0000000..8e0dc37 --- /dev/null +++ b/lib/object_inspection_behaviors.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# ObjectInspectionBehaviors is an interface layer to the inspection helper in +# the object_inspector gem. Using this approach, we are able to e.g. +# conditionally enable object_inspector throughout the entire app. +module ObjectInspectionBehaviors + unless App.debug? # rubocop:disable Style/IfUnlessModifier + include ObjectInspector::InspectorsHelper + end +end