column_anonymizer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/WORKFLOW_GUIDE.md ADDED
@@ -0,0 +1,368 @@
1
+ # Column Anonymizer - Workflow Guide
2
+
3
+ ## ๐ŸŽฏ Quick Reference
4
+
5
+ ### Installation Options
6
+
7
+ #### Option 1: Install + Auto-Scan (Recommended) โญ
8
+ ```bash
9
+ rails generate column_anonymizer:install --scan
10
+ ```
11
+ **What happens:**
12
+ 1. Creates `config/encrypted_columns.yml`
13
+ 2. Scans all models for `encrypts` calls
14
+ 3. Populates YAML with detected columns
15
+ 4. Ready to use immediately!
16
+
17
+ #### Option 2: Install Then Scan Separately
18
+ ```bash
19
+ rails generate column_anonymizer:install
20
+ rails generate column_anonymizer:scan
21
+ ```
22
+ **What happens:**
23
+ 1. Creates empty `config/encrypted_columns.yml` template
24
+ 2. Then scans and populates it
25
+ 3. Same result as Option 1
26
+
27
+ #### Option 3: Manual Configuration
28
+ ```bash
29
+ rails generate column_anonymizer:install
30
+ # Edit config/encrypted_columns.yml manually
31
+ ```
32
+ **What happens:**
33
+ 1. Creates `config/encrypted_columns.yml` template
34
+ 2. You manually add all models and columns
35
+ 3. More control, more work
36
+
37
+ ---
38
+
39
+ ## ๐Ÿ“Š Workflow Diagrams
40
+
41
+ ### Auto-Scan Workflow (Recommended)
42
+
43
+ ```
44
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
45
+ โ”‚ rails generate column_anonymizer:install --scan โ”‚
46
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
47
+ โ”‚
48
+ โ–ผ
49
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
50
+ โ”‚ Create config file โ”‚
51
+ โ”‚ config/encrypted_ โ”‚
52
+ โ”‚ columns.yml โ”‚
53
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
54
+ โ”‚
55
+ โ–ผ
56
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
57
+ โ”‚ Scan app/models/ โ”‚
58
+ โ”‚ directory โ”‚
59
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
60
+ โ”‚
61
+ โ–ผ
62
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
63
+ โ”‚ Find all 'encrypts' โ”‚
64
+ โ”‚ method calls โ”‚
65
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
66
+ โ”‚
67
+ โ–ผ
68
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
69
+ โ”‚ Guess column types โ”‚
70
+ โ”‚ based on names โ”‚
71
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
72
+ โ”‚
73
+ โ–ผ
74
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
75
+ โ”‚ Update YAML config โ”‚
76
+ โ”‚ with discovered โ”‚
77
+ โ”‚ columns โ”‚
78
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
79
+ โ”‚
80
+ โ–ผ
81
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
82
+ โ”‚ โœ… Ready to anonymize! โ”‚
83
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
84
+ ```
85
+
86
+ ### Manual Configuration Workflow
87
+
88
+ ```
89
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
90
+ โ”‚ rails generate โ”‚
91
+ โ”‚ column_anonymizer:install โ”‚
92
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
93
+ โ”‚
94
+ โ–ผ
95
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
96
+ โ”‚ Create empty โ”‚
97
+ โ”‚ config file โ”‚
98
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
99
+ โ”‚
100
+ โ–ผ
101
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
102
+ โ”‚ Manually edit โ”‚
103
+ โ”‚ YAML file โ”‚
104
+ โ”‚ (tedious!) โ”‚
105
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
106
+ โ”‚
107
+ โ–ผ
108
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
109
+ โ”‚ Add each model โ”‚
110
+ โ”‚ and column โ”‚
111
+ โ”‚ by hand โ”‚
112
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
113
+ โ”‚
114
+ โ–ผ
115
+ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
116
+ โ”‚ Ready to use โ”‚
117
+ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
118
+ ```
119
+
120
+ ---
121
+
122
+ ## ๐Ÿ”„ Adding New Encrypted Columns
123
+
124
+ ### When You Add New Models
125
+
126
+ ```ruby
127
+ # 1. Create a new model with encrypted attributes
128
+ class Patient < ApplicationRecord
129
+ encrypts :medical_record_number
130
+ encrypts :emergency_contact_phone
131
+ end
132
+
133
+ # 2. Run the scanner
134
+ # rails generate column_anonymizer:scan
135
+
136
+ # 3. Output shows:
137
+ # ๐Ÿ” Scanning models...
138
+ # โ„น๏ธ Skipping User.email (already configured)
139
+ # โž• Adding Patient.medical_record_number as 'text'
140
+ # โž• Adding Patient.emergency_contact_phone as 'phone'
141
+ # โœ… Updated config/encrypted_columns.yml
142
+ ```
143
+
144
+ ### Smart Merging
145
+
146
+ The scanner **never overwrites** existing configuration:
147
+
148
+ ```yaml
149
+ # Before scan:
150
+ User:
151
+ email: email # โ† Stays as-is
152
+
153
+ # After adding new Patient model and running scan:
154
+ User:
155
+ email: email # โ† Preserved!
156
+
157
+ Patient:
158
+ medical_record_number: text # โ† Added
159
+ emergency_contact_phone: phone # โ† Added
160
+ ```
161
+
162
+ ---
163
+
164
+ ## ๐Ÿง  Type Guessing Examples
165
+
166
+ ### Common Column Names โ†’ Auto-Detected Types
167
+
168
+ ```ruby
169
+ class User < ApplicationRecord
170
+ encrypts :email # โ†’ type: email
171
+ encrypts :phone_number # โ†’ type: phone
172
+ encrypts :mobile # โ†’ type: phone
173
+ encrypts :ssn # โ†’ type: ssn
174
+ encrypts :social_security_number # โ†’ type: ssn
175
+ encrypts :first_name # โ†’ type: first_name
176
+ encrypts :last_name # โ†’ type: last_name
177
+ encrypts :full_name # โ†’ type: name
178
+ encrypts :home_address # โ†’ type: address
179
+ encrypts :street_address # โ†’ type: address
180
+ encrypts :credit_card_number # โ†’ type: text
181
+ encrypts :api_token # โ†’ type: text
182
+ encrypts :password_digest # โ†’ type: text
183
+ encrypts :custom_field # โ†’ type: text (default)
184
+ end
185
+ ```
186
+
187
+ ### Resulting YAML
188
+
189
+ ```yaml
190
+ User:
191
+ email: email
192
+ phone_number: phone
193
+ mobile: phone
194
+ ssn: ssn
195
+ social_security_number: ssn
196
+ first_name: first_name
197
+ last_name: last_name
198
+ full_name: name
199
+ home_address: address
200
+ street_address: address
201
+ credit_card_number: text
202
+ api_token: text
203
+ password_digest: text
204
+ custom_field: text
205
+ ```
206
+
207
+ ---
208
+
209
+ ## ๐ŸŽจ Customizing Auto-Detected Types
210
+
211
+ You can always override the auto-detected types:
212
+
213
+ ```bash
214
+ # 1. Run scanner
215
+ rails generate column_anonymizer:scan
216
+
217
+ # 2. Review config/encrypted_columns.yml
218
+
219
+ # 3. Manually adjust any incorrect guesses
220
+ ```
221
+
222
+ **Example:**
223
+
224
+ ```yaml
225
+ # Auto-detected (might be wrong):
226
+ User:
227
+ contact_info: text # โ† Guessed 'text'
228
+
229
+ # Manually corrected:
230
+ User:
231
+ contact_info: phone # โ† You know it's a phone number
232
+ ```
233
+
234
+ ---
235
+
236
+ ## ๐Ÿ“ Complete Example
237
+
238
+ ### Step-by-Step
239
+
240
+ ```bash
241
+ # 1. Add gem to Gemfile
242
+ echo "gem 'column_anonymizer'" >> Gemfile
243
+ bundle install
244
+
245
+ # 2. Install with auto-scan
246
+ rails generate column_anonymizer:install --scan
247
+
248
+ # Output:
249
+ # โœ… Created config/encrypted_columns.yml
250
+ # ๐Ÿ” Scanning models for encrypted attributes...
251
+ # โž• Adding User.email as 'email'
252
+ # โž• Adding User.phone as 'phone'
253
+ # โž• Adding User.ssn as 'ssn'
254
+ # โœ… Scanned 1 model(s)
255
+ # ๐Ÿ“ Updated config/encrypted_columns.yml
256
+
257
+ # 3. Check the config
258
+ cat config/encrypted_columns.yml
259
+
260
+ # Output:
261
+ # ---
262
+ # User:
263
+ # email: email
264
+ # phone: phone
265
+ # ssn: ssn
266
+
267
+ # 4. Anonymize data
268
+ rails console
269
+ ```
270
+
271
+ ```ruby
272
+ # In console:
273
+ user = User.first
274
+ ColumnAnonymizer::Anonymizer.anonymize_model!(user)
275
+ user.reload
276
+
277
+ puts user.email # => "user_abc12345@example.com"
278
+ puts user.phone # => "+15551234567"
279
+ puts user.ssn # => "123-45-6789"
280
+ ```
281
+
282
+ ---
283
+
284
+ ## ๐Ÿš€ Pro Tips
285
+
286
+ ### Tip 1: Run Scan After Model Changes
287
+ ```bash
288
+ # After adding encrypts to existing models
289
+ rails generate column_anonymizer:scan
290
+ # Only new columns are added
291
+ ```
292
+
293
+ ### Tip 2: Review Auto-Detections
294
+ ```bash
295
+ # Always review the generated YAML
296
+ cat config/encrypted_columns.yml
297
+ # Adjust types if needed
298
+ ```
299
+
300
+ ### Tip 3: Use in CI/CD
301
+ ```bash
302
+ # Add to your deployment script
303
+ rails generate column_anonymizer:scan --quiet
304
+ # Keeps config in sync with models
305
+ ```
306
+
307
+ ### Tip 4: Safe to Run Multiple Times
308
+ ```bash
309
+ # No risk of data loss
310
+ rails generate column_anonymizer:scan
311
+ rails generate column_anonymizer:scan
312
+ rails generate column_anonymizer:scan
313
+ # Always safe - never overwrites!
314
+ ```
315
+
316
+ ---
317
+
318
+ ## โšก Quick Command Reference
319
+
320
+ | Command | What It Does | When to Use |
321
+ |---------|--------------|-------------|
322
+ | `rails g column_anonymizer:install --scan` | Install + auto-configure | First time setup โญ |
323
+ | `rails g column_anonymizer:scan` | Update config with new models | After adding encrypts |
324
+ | `rails g column_anonymizer:install` | Install empty config | Manual configuration |
325
+ | `ColumnAnonymizer::SchemaLoader.reload_schema!` | Reload in console | Development/testing |
326
+
327
+ ---
328
+
329
+ ## ๐ŸŽฏ Decision Tree
330
+
331
+ ```
332
+ Do you have models with 'encrypts' already?
333
+ โ”‚
334
+ โ”œโ”€ YES โ†’ Use: rails g column_anonymizer:install --scan โญ
335
+ โ”‚ (Fastest! Everything auto-configured)
336
+ โ”‚
337
+ โ””โ”€ NO โ†’ Use: rails g column_anonymizer:install
338
+ Then add encrypts to models
339
+ Then run: rails g column_anonymizer:scan
340
+ ```
341
+
342
+ ---
343
+
344
+ ## ๐Ÿ“š Related Files
345
+
346
+ - `README.md` - Complete documentation
347
+ - `IMPLEMENTATION_SUMMARY.md` - Technical details
348
+ - `SCAN_GENERATOR_TEST.md` - Testing guide
349
+ - `YAML_MIGRATION_GUIDE.md` - Migration from old approach
350
+ - `CHANGELOG.md` - Version history
351
+
352
+ ---
353
+
354
+ ## ๐ŸŽ‰ Summary
355
+
356
+ **Before this feature:**
357
+ - Manual YAML editing required
358
+ - Prone to typos and errors
359
+ - Time-consuming setup
360
+
361
+ **After this feature:**
362
+ - One command: `rails g column_anonymizer:install --scan`
363
+ - Automatic discovery and configuration
364
+ - Intelligent type detection
365
+ - Safe to run multiple times
366
+ - Ready to use in seconds!
367
+
368
+ **The Power of Automation!** ๐Ÿš€
@@ -0,0 +1,284 @@
1
+ # Column Encrypter Gem - YAML-Based Configuration
2
+
3
+ ## โœ… Gem Successfully Refactored!
4
+
5
+ The gem has been refactored from method-based configuration to YAML-based configuration.
6
+
7
+ ## ๐ŸŽฏ Key Changes
8
+
9
+ ### Before (Method-Based):
10
+ ```ruby
11
+ class User < ApplicationRecord
12
+ encrypts_with_type :email, :email
13
+ encrypts_with_type :phone_number, :phone
14
+ end
15
+ ```
16
+
17
+ ### After (YAML-Based):
18
+ ```yaml
19
+ # config/encrypted_columns.yml
20
+ User:
21
+ email: email
22
+ phone_number: phone
23
+ ```
24
+
25
+ ```ruby
26
+ class User < ApplicationRecord
27
+ encrypts :email
28
+ encrypts :phone_number
29
+ end
30
+ ```
31
+
32
+ ## ๐Ÿ“ Gem Structure
33
+
34
+ ```
35
+ column_anonymizer/
36
+ โ”œโ”€โ”€ lib/
37
+ โ”‚ โ”œโ”€โ”€ column_anonymizer.rb # Main entry point
38
+ โ”‚ โ”œโ”€โ”€ column_anonymizer/
39
+ โ”‚ โ”‚ โ”œโ”€โ”€ version.rb # Version: 0.1.0
40
+ โ”‚ โ”‚ โ”œโ”€โ”€ schema_loader.rb # Loads YAML configuration
41
+ โ”‚ โ”‚ โ”œโ”€โ”€ encryptable.rb # Reads types from YAML
42
+ โ”‚ โ”‚ โ”œโ”€โ”€ anonymizer.rb # Data anonymization
43
+ โ”‚ โ”‚ โ””โ”€โ”€ railtie.rb # Rails integration
44
+ โ”‚ โ””โ”€โ”€ generators/
45
+ โ”‚ โ””โ”€โ”€ column_anonymizer/
46
+ โ”‚ โ”œโ”€โ”€ install/
47
+ โ”‚ โ”‚ โ”œโ”€โ”€ install_generator.rb # Rails generator
48
+ โ”‚ โ”‚ โ”œโ”€โ”€ templates/
49
+ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ encrypted_columns.yml # YAML template
50
+ โ”‚ โ”‚ โ””โ”€โ”€ README # Installation instructions
51
+ โ”‚ โ””โ”€โ”€ scan/
52
+ โ”‚ โ””โ”€โ”€ scan_generator.rb # โญ Auto-discovery scanner
53
+ โ”œโ”€โ”€ spec/
54
+ โ”‚ โ”œโ”€โ”€ column_anonymizer_spec.rb # Tests
55
+ โ”‚ โ””โ”€โ”€ spec_helper.rb # Test configuration
56
+ โ”œโ”€โ”€ column_anonymizer.gemspec # Gem specification
57
+ โ”œโ”€โ”€ Gemfile # Dependencies
58
+ โ”œโ”€โ”€ Rakefile # Rake tasks
59
+ โ”œโ”€โ”€ README.md # Documentation
60
+ โ””โ”€โ”€ CHANGELOG.md # Version history
61
+ ```
62
+
63
+ ## ๐Ÿš€ Installation & Usage
64
+
65
+ ### 1. Install the Gem
66
+
67
+ ```bash
68
+ # Add to Gemfile
69
+ gem 'column_encrypter', path: '/Users/hkend/Documents/column_encrypter/column_encrypter'
70
+
71
+ # Or install locally
72
+ cd /Users/hkend/Documents/column_encrypter/column_encrypter
73
+ gem build column_encrypter.gemspec
74
+ gem install column_encrypter-0.1.0.gem
75
+ ```
76
+
77
+ ### 2. Generate Configuration File
78
+
79
+ ```bash
80
+ rails generate column_anonymizer:install
81
+ ```
82
+
83
+ This creates `config/encrypted_columns.yml`.
84
+
85
+ ### 3. Define Your Schema
86
+
87
+ **Option A: Automatic Scanning (Recommended)**
88
+
89
+ The gem can automatically scan your models and populate the YAML file:
90
+
91
+ ```bash
92
+ # Scan existing models and update config
93
+ rails generate column_anonymizer:scan
94
+
95
+ # Or install and scan in one step
96
+ rails generate column_anonymizer:install --scan
97
+ ```
98
+
99
+ The scanner will:
100
+ - Find all models with `encrypts` calls
101
+ - Intelligently guess the data type based on column names
102
+ - Add new columns to your config without overwriting existing entries
103
+ - Show you what was discovered
104
+
105
+ **Option B: Manual Configuration**
106
+
107
+ Edit `config/encrypted_columns.yml`:
108
+
109
+ ```yaml
110
+ User:
111
+ email: email
112
+ phone_number: phone
113
+ ssn: ssn
114
+ full_name: name
115
+
116
+ Account:
117
+ bank_account_number: text
118
+ routing_number: text
119
+ ```
120
+
121
+ ### 4. Use Standard Rails Encryption
122
+
123
+ ```ruby
124
+ class User < ApplicationRecord
125
+ encrypts :email
126
+ encrypts :phone_number
127
+ encrypts :ssn
128
+ encrypts :full_name
129
+ end
130
+ ```
131
+
132
+ ### 5. Anonymize Data
133
+
134
+ ```ruby
135
+ # In console or rake task
136
+ user = User.first
137
+ ColumnEncrypter::Anonymizer.anonymize_model!(user)
138
+
139
+ # email becomes: user_a1b2c3d4@example.com
140
+ # phone_number becomes: +15551234567
141
+ # ssn becomes: 123-45-6789
142
+ # full_name becomes: Anonymous User abc123
143
+ ```
144
+
145
+ ## ๐ŸŽจ Built-in Generators
146
+
147
+ | Type | Example Output |
148
+ |------|----------------|
149
+ | `:email` | `user_a1b2c3d4@example.com` |
150
+ | `:phone` | `+15551234567` |
151
+ | `:ssn` | `123-45-6789` |
152
+ | `:name` | `Anonymous User abc123` |
153
+ | `:first_name` | `John`, `Jane`, `Alex` |
154
+ | `:last_name` | `Smith`, `Johnson` |
155
+ | `:address` | `1234 Anonymous St, City, ST 12345` |
156
+ | `:text` | `Anonymized text a1b2c3d4` |
157
+
158
+ ## ๐Ÿง  Intelligent Type Guessing
159
+
160
+ When you use `rails generate column_anonymizer:scan`, the generator intelligently guesses the data type based on column names:
161
+
162
+ | Column Name Pattern | Detected Type |
163
+ |---------------------|---------------|
164
+ | `email` | `:email` |
165
+ | `phone`, `mobile`, `cell`, `telephone` | `:phone` |
166
+ | `ssn`, `social_security` | `:ssn` |
167
+ | `first_name`, `fname` | `:first_name` |
168
+ | `last_name`, `lname`, `surname` | `:last_name` |
169
+ | `name`, `full_name`, `fullname` | `:name` |
170
+ | `address`, `street`, `addr` | `:address` |
171
+ | `card_number`, `credit_card`, `cvv`, `cvc` | `:text` |
172
+ | `password`, `token`, `secret` | `:text` |
173
+ | Everything else | `:text` |
174
+
175
+ You can always manually adjust the types in `config/encrypted_columns.yml` after scanning.
176
+
177
+ ## โœจ Benefits of YAML Approach
178
+
179
+ 1. **Centralized Configuration**: All column types in one place
180
+ 2. **No Code Changes**: Just use standard Rails `encrypts` method
181
+ 3. **Easy Updates**: Modify schema without touching model files
182
+ 4. **Automatic Discovery**: Scan feature finds encrypted columns automatically
183
+ 5. **Smart Type Guessing**: Intelligently detects appropriate anonymization types
184
+ 4. **Better Organization**: Clear overview of all encrypted columns
185
+ 5. **Version Control Friendly**: YAML changes are easy to review
186
+
187
+ ## ๐Ÿ”„ Schema Reloading (Development)
188
+
189
+ ```ruby
190
+ # In Rails console
191
+ ColumnEncrypter::SchemaLoader.reload_schema!
192
+ User.reload_encrypted_columns_metadata!
193
+ ```
194
+
195
+ ## ๐Ÿ“ Example YAML Schema
196
+
197
+ ```yaml
198
+ # config/encrypted_columns.yml
199
+
200
+ User:
201
+ email: email
202
+ phone_number: phone
203
+ ssn: ssn
204
+ first_name: first_name
205
+ last_name: last_name
206
+ home_address: address
207
+ date_of_birth: text
208
+
209
+ Patient:
210
+ medical_record_number: text
211
+ ssn: ssn
212
+ emergency_contact_phone: phone
213
+ email: email
214
+
215
+ CreditCard:
216
+ card_number: text
217
+ cvv: text
218
+ cardholder_name: name
219
+ billing_address: address
220
+ ```
221
+
222
+ ## ๐Ÿงช Testing in Rails Console
223
+
224
+ ```bash
225
+ # Add gem to your Rails app's Gemfile
226
+ gem 'column_encrypter', path: '/Users/hkend/Documents/column_encrypter/column_encrypter'
227
+
228
+ bundle install
229
+ rails generate column_encrypter:install
230
+ rails console
231
+ ```
232
+
233
+ Then in console:
234
+
235
+ ```ruby
236
+ # Create the schema
237
+ File.write('config/encrypted_columns.yml', <<~YAML)
238
+ User:
239
+ email: email
240
+ phone: phone
241
+ YAML
242
+
243
+ # Reload schema
244
+ ColumnEncrypter::SchemaLoader.reload_schema!
245
+
246
+ # Check metadata
247
+ User.encrypted_columns_metadata
248
+ # => {:email=>:email, :phone=>:phone}
249
+
250
+ # Anonymize
251
+ user = User.first
252
+ ColumnEncrypter::Anonymizer.anonymize_model!(user)
253
+ ```
254
+
255
+ ## ๐Ÿ“ฆ Files Created
256
+
257
+ - โœ… `lib/column_encrypter.rb` - Main entry point
258
+ - โœ… `lib/column_encrypter/version.rb` - Version
259
+ - โœ… `lib/column_encrypter/schema_loader.rb` - YAML loader
260
+ - โœ… `lib/column_encrypter/encryptable.rb` - ActiveRecord integration
261
+ - โœ… `lib/column_encrypter/anonymizer.rb` - Data generators
262
+ - โœ… `lib/column_encrypter/railtie.rb` - Rails auto-loading
263
+ - โœ… `lib/generators/column_encrypter/install/install_generator.rb` - Generator
264
+ - โœ… `lib/generators/column_encrypter/install/templates/encrypted_columns.yml` - Template
265
+ - โœ… `lib/generators/column_encrypter/install/README` - Install instructions
266
+ - โœ… `spec/column_encrypter_spec.rb` - Tests
267
+ - โœ… `spec/spec_helper.rb` - Test configuration
268
+ - โœ… `column_encrypter.gemspec` - Gem specification
269
+ - โœ… `Gemfile` - Dependencies
270
+ - โœ… `Rakefile` - Rake tasks
271
+ - โœ… `README.md` - Complete documentation
272
+ - โœ… `CHANGELOG.md` - Version history
273
+
274
+ ## ๐ŸŽ‰ Ready to Use!
275
+
276
+ The gem is complete with YAML-based configuration. You can now:
277
+
278
+ 1. Install it in your Rails app
279
+ 2. Run `rails generate column_encrypter:install`
280
+ 3. Define your schema in `config/encrypted_columns.yml`
281
+ 4. Use standard Rails `encrypts` method
282
+ 5. Anonymize data with `ColumnEncrypter::Anonymizer.anonymize_model!(record)`
283
+
284
+ **Location:** `/Users/hkend/Documents/column_encrypter/column_encrypter/`