Skip to content

Conversation

@stevepolitodesign
Copy link
Contributor

Follow-up to #89.

Now that we enforce a specific label format, we can dynamically generate
methods based on the types of data that was filtered.

result = TopSecret::Text.filter("Ralph can be reached at ralph@example.com")

result.emails?
# => true
result.emails
# => ["ralph@example.com"]
result.email_mapping
# => {EMAIL_1 => "ralph@example.com"}

result.people?
# => true
result.people
# => ["Ralph"]
result.email_mapping
# => {PERSON_1 => "Ralph"}

result.credit_cards?
# => false
result.credit_cards
# => []
result.credit_card_mapping
# => {}

Copilot AI review requested due to automatic review settings November 7, 2025 21:38
@stevepolitodesign stevepolitodesign force-pushed the sp-generated-categoy-methods branch from 4c5b543 to 2deb1cf Compare November 7, 2025 21:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds dynamic categorization functionality to the TopSecret::Mapping module, enabling results to be queried by sensitive data types through dynamically generated accessor methods. The changes introduce a flexible method-missing-based approach to access categorized sensitive information.

  • Introduces dynamic method generation for accessing sensitive data by category (e.g., emails, credit_cards, people)
  • Adds a LABEL_DELIMITER constant and updates label generation to use it consistently
  • Extends test coverage with comprehensive tests for categorization features

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
lib/top_secret/constants.rb Adds LABEL_DELIMITER constant for consistent label formatting
lib/top_secret/text/global_mapping.rb Updates label generation to use the new LABEL_DELIMITER constant
lib/top_secret/mapping.rb Implements dynamic method generation via method_missing for categorization accessors, predicates, and mapping methods
spec/top_secret/text_spec.rb Adds comprehensive tests for categorization features in both .filter and .filter_all methods
spec/top_secret/result_spec.rb Adds tests for categorization behavior and dynamic method responses

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

PERSON_1: "Ralph",
IP_ADDRESS_1: "192.168.1.1",
CREDIT_CARD_NUMBER_1: "4242424242424242",
NETWORK_MAPPING_1: "10.0.1.0/24 -> 192.168.1.0/24"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should test something like {WORD}_MAPPING_{WORD}_{N} to ensure that works too.

README.md Outdated
result.email_mapping # => {}
```

When using custom labels, methods are generated based on the label name:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also highlight that emails works too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some work. It's actually a false-positive that it was returning data before. I think that's because they both started with EMAIL_.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what should we do if we disable a filter? Should those methods still exist?

@stevepolitodesign stevepolitodesign force-pushed the sp-generated-categoy-methods branch from 2deb1cf to 76021bd Compare November 7, 2025 23:53
Follow-up to #89.

Now that we enforce a specific label format, we can dynamically generate
methods based on the types of data that was filtered.

```ruby
result = TopSecret::Text.filter("Ralph can be reached at ralph@example.com")

result.emails?
=> true
result.emails
=> ["ralph@example.com"]
result.email_mapping
=> {EMAIL_1 => "ralph@example.com"}

result.people?
=> true
result.people
=> ["Ralph"]
result.email_mapping
=> {PERSON_1 => "Ralph"}

result.credit_cards?
=> false
result.credit_cards
 => []
result.credit_card_mapping
=> {}
```
@stevepolitodesign stevepolitodesign force-pushed the sp-generated-categoy-methods branch from 76021bd to 69b1f8c Compare November 7, 2025 23:57
@github-actions
Copy link

github-actions bot commented Dec 8, 2025

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions
Copy link

github-actions bot commented Jan 8, 2026

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants