whodunit 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b45b1b2f4cfb91e98e2c4656c67305403108af39c5069127d91f0521599bc94
4
- data.tar.gz: 56472d61e9f422643eefe7dca84b7f050fa8d91bb4274bb2354a4e01f04d5ee4
3
+ metadata.gz: 1ce926c88b69914bd703491e1bf11f890f64a4c4f5679929d1b898306ea18fcd
4
+ data.tar.gz: 3b277cf8bbf1f36e494f90f959941c38b3829f541b5b36b1168b98a276d830f7
5
5
  SHA512:
6
- metadata.gz: c959a0b51f441b28a855b95a537e5983592ed5eb7eef4cbf5eb42c1d4c120849a27ac4113c784f27defa6703939d6cb02a0c2ccc8bd24f0a0508673351407b97
7
- data.tar.gz: a5ca68eebccf5794c9b65521a0c7a232f3178d7aacb6af89c9de3b3bc1365588a6e62a39c52c9821987aaa8735231d289fbc1f28fc7a95be391171d40afbfe31
6
+ metadata.gz: 68b739ee97b145af1451991f589dfd9353da7ff579592e9f45071c532ed095e2b83e166b30b987bdbd6a22f1f47b421d1dc76fce7818491889376a0249ecdd21
7
+ data.tar.gz: 3796e3c88a21640063c504d27f3fa34a16f077eac5653826cd7a0a4ad513288dec0aa88383afa633daac57d25719711e2325cc33e01079f00725f76d2d22270d
data/.rubocop.yml CHANGED
@@ -13,6 +13,7 @@ AllCops:
13
13
  - 'coverage/**/*'
14
14
  - 'bin/**/*'
15
15
  - 'sig/**/*'
16
+ - 'example/**/*'
16
17
 
17
18
  # Layout & Formatting
18
19
  Layout/LineLength:
data/CHANGELOG.md CHANGED
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.1] - 2025-01-21
11
+
12
+ ### Added
13
+
14
+ - **ApplicationRecord Integration**: `whodunit install` now prompts to automatically add `Whodunit::Stampable` to `ApplicationRecord` for convenient all-model stamping
15
+ - **Enhanced Configuration Template**: Detailed explanations and examples for each configuration option in generated initializer
16
+ - **Post-install Message**: Helpful instructions displayed after gem installation via `bundle add whodunit`
17
+ - **Comprehensive Test Coverage**: Full test suite for ApplicationRecord integration with edge case handling
18
+
19
+ ### Changed
20
+
21
+ - **Improved CLI Experience**: More user-friendly prompts and messages throughout the installation process
22
+ - **Better Documentation**: Updated README with corrected installation commands and new ApplicationRecord feature
23
+ - **Code Organization**: Extracted ApplicationRecord integration logic into separate module for better maintainability
24
+
25
+ ### Fixed
26
+
27
+ - **Gemspec Consistency**: Corrected post-install message to show `whodunit install` instead of incorrect Rails generator command
28
+ - **RuboCop Compliance**: Fixed all style issues and reduced complexity across codebase
29
+
10
30
  ## [0.2.0] - 2025-01-20
11
31
 
12
32
  ### Added
data/README.md CHANGED
@@ -34,6 +34,23 @@ And then execute:
34
34
 
35
35
  $ bundle install
36
36
 
37
+ ### What's Next?
38
+
39
+ After installation, you have a few options:
40
+
41
+ 1. **Generate Configuration & Setup** (Recommended):
42
+ ```bash
43
+ whodunit install
44
+ ```
45
+ This will:
46
+ - Create `config/initializers/whodunit.rb` with all available configuration options
47
+ - Optionally add `Whodunit::Stampable` to your `ApplicationRecord` for automatic stamping on all models
48
+ - Provide clear next steps for adding stamp columns to your database
49
+
50
+ 2. **Quick Setup**: Jump directly to adding stamp columns to your models (see Quick Start below)
51
+
52
+ 3. **Learn More**: Check the [Complete Documentation](https://kanutocd.github.io/whodunit) for advanced configuration
53
+
37
54
  ## Quick Start
38
55
 
39
56
  ### 1. Add Stamp Columns
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Whodunit
4
+ class Generator
5
+ # Handles ApplicationRecord integration functionality
6
+ module ApplicationRecordIntegration
7
+ def self.handle_application_record_integration!
8
+ application_record_file = "app/models/application_record.rb"
9
+
10
+ return unless application_record_exists?(application_record_file)
11
+
12
+ content = File.read(application_record_file)
13
+ return if stampable_already_included?(content)
14
+
15
+ return unless user_wants_application_record_integration?
16
+
17
+ add_stampable_to_application_record!(application_record_file, content)
18
+ end
19
+
20
+ private_class_method def self.application_record_exists?(file_path)
21
+ return true if File.exist?(file_path)
22
+
23
+ puts "⚠️ ApplicationRecord not found at #{file_path}"
24
+ false
25
+ end
26
+
27
+ private_class_method def self.stampable_already_included?(content)
28
+ return false unless content.include?("Whodunit::Stampable")
29
+
30
+ puts "✅ Whodunit::Stampable already included in ApplicationRecord"
31
+ true
32
+ end
33
+
34
+ private_class_method def self.user_wants_application_record_integration?
35
+ puts ""
36
+ puts "🤔 Do you want to include Whodunit::Stampable in ApplicationRecord?"
37
+ puts " This will automatically enable stamping for ALL your models."
38
+ puts " (You can always include it manually in specific models instead)"
39
+ print " Add to ApplicationRecord? (Y/n): "
40
+
41
+ response = $stdin.gets.chomp.downcase
42
+ !%w[n no].include?(response)
43
+ end
44
+
45
+ private_class_method def self.add_stampable_to_application_record!(file_path, content)
46
+ updated_content = try_primary_pattern(content) || try_fallback_pattern(content)
47
+
48
+ if updated_content
49
+ write_updated_application_record!(file_path, updated_content)
50
+ else
51
+ show_manual_integration_message
52
+ end
53
+ end
54
+
55
+ private_class_method def self.try_primary_pattern(content)
56
+ return unless content.match?(/^(\s*class ApplicationRecord < ActiveRecord::Base\s*)$/)
57
+
58
+ content.gsub(
59
+ /^(\s*class ApplicationRecord < ActiveRecord::Base\s*)$/,
60
+ "\\1\n include Whodunit::Stampable"
61
+ )
62
+ end
63
+
64
+ private_class_method def self.try_fallback_pattern(content)
65
+ return unless content.match?(/^(\s*class ApplicationRecord.*\n)/)
66
+
67
+ content.gsub(
68
+ /^(\s*class ApplicationRecord.*\n)/,
69
+ "\\1 include Whodunit::Stampable\n"
70
+ )
71
+ end
72
+
73
+ private_class_method def self.write_updated_application_record!(file_path, content)
74
+ File.write(file_path, content)
75
+ puts "✅ Added Whodunit::Stampable to ApplicationRecord"
76
+ puts " All your models will now automatically include stamping!"
77
+ end
78
+
79
+ private_class_method def self.show_manual_integration_message
80
+ puts "⚠️ Could not automatically modify ApplicationRecord"
81
+ puts " Please manually add: include Whodunit::Stampable"
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fileutils"
4
+ require_relative "generator/application_record_integration"
4
5
 
5
6
  module Whodunit
6
7
  # Generator for creating Whodunit configuration files
@@ -13,18 +14,48 @@ module Whodunit
13
14
  # Uncomment and modify the options you want to customize.
14
15
 
15
16
  # Whodunit.configure do |config|
17
+ # # User model configuration
18
+ # # Specify which model represents users in your application
16
19
  # config.user_class = 'Account' # Default: 'User'
20
+ # # Use 'Account', 'Admin', etc. if your user model has a different name
21
+ #
22
+ # # Column name configuration
23
+ # # Customize the names of the tracking columns in your database
17
24
  # config.creator_column = :created_by_id # Default: :creator_id
25
+ # # Column that stores who created the record
18
26
  # config.updater_column = :updated_by_id # Default: :updater_id
27
+ # # Column that stores who last updated the record
19
28
  # config.deleter_column = :deleted_by_id # Default: :deleter_id
20
- # config.soft_delete_column = :discarded_at # Default: nil
29
+ # # Column that stores who deleted the record (soft-delete only)
30
+ #
31
+ # # Soft-delete integration
32
+ # # Enable tracking of who deleted records when using soft-delete gems
33
+ # config.soft_delete_column = :discarded_at # Default: nil (disabled)
34
+ # # Set to :deleted_at for Paranoia gem
35
+ # # Set to :discarded_at for Discard gem
36
+ # # Set to your custom soft-delete column name
37
+ # # Set to nil to disable soft-delete tracking
38
+ #
39
+ # # Migration auto-injection
40
+ # # Control whether whodunit stamps are automatically added to new migrations
21
41
  # config.auto_inject_whodunit_stamps = false # Default: true
42
+ # # When true, automatically adds t.whodunit_stamps to create_table migrations
43
+ # # When false, you must manually add t.whodunit_stamps to your migrations
22
44
  #
23
45
  # # Column data type configuration
24
- # config.column_data_type = :integer # Default: :bigint (applies to all columns)
46
+ # # Configure what data types to use for the tracking columns
47
+ # config.column_data_type = :integer # Default: :bigint
48
+ # # Global default for all stamp columns
49
+ # # Common options: :bigint, :integer, :string, :uuid
50
+ #
51
+ # # Individual column type overrides
52
+ # # Override the data type for specific columns (takes precedence over column_data_type)
25
53
  # config.creator_column_type = :string # Default: nil (uses column_data_type)
54
+ # # Useful if your user IDs are strings or UUIDs
26
55
  # config.updater_column_type = :uuid # Default: nil (uses column_data_type)
56
+ # # Set to match your user model's primary key type
27
57
  # config.deleter_column_type = :integer # Default: nil (uses column_data_type)
58
+ # # Only used when soft_delete_column is configured
28
59
  # end
29
60
  RUBY
30
61
 
@@ -36,6 +67,7 @@ module Whodunit
36
67
  ensure_config_directory_exists!(config_dir)
37
68
  handle_existing_file!(config_file)
38
69
  create_initializer_file!(config_file)
70
+ ApplicationRecordIntegration.handle_application_record_integration!
39
71
  show_success_message(config_file)
40
72
  end
41
73
 
@@ -76,7 +108,10 @@ module Whodunit
76
108
  puts "📝 Next steps:"
77
109
  puts " 1. Edit #{config_file} to customize your configuration"
78
110
  puts " 2. Uncomment the options you want to change"
79
- puts " 3. Restart your Rails server to apply changes"
111
+ puts " 3. Add stamp columns to your models with migrations:"
112
+ puts " rails generate migration AddStampsToUsers"
113
+ puts " # Then add: add_whodunit_stamps :users"
114
+ puts " 4. Restart your Rails server to apply changes"
80
115
  puts ""
81
116
  puts "📖 For more information, see: https://github.com/kanutocd/whodunit?tab=readme-ov-file#configuration"
82
117
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whodunit
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whodunit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken C. Demanawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-07-20 00:00:00.000000000 Z
11
+ date: 2025-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -217,6 +217,7 @@ files:
217
217
  - lib/whodunit/controller_methods.rb
218
218
  - lib/whodunit/current.rb
219
219
  - lib/whodunit/generator.rb
220
+ - lib/whodunit/generator/application_record_integration.rb
220
221
  - lib/whodunit/migration_helpers.rb
221
222
  - lib/whodunit/railtie.rb
222
223
  - lib/whodunit/stampable.rb
@@ -234,7 +235,11 @@ metadata:
234
235
  bug_tracker_uri: https://github.com/kanutocd/whodunit/issues
235
236
  documentation_uri: https://kanutocd.github.io/whodunit
236
237
  rubygems_mfa_required: 'true'
237
- post_install_message:
238
+ post_install_message: "\U0001F389 Thanks for installing Whodunit!\n\nWhat's next?\n\n1.
239
+ Generate configuration (recommended):\n whodunit install\n\n2. Add stamp columns
240
+ to your models:\n rails generate migration AddStampsToUsers\n # Then add: add_whodunit_stamps
241
+ :users\n\n3. Include Whodunit::Stampable in your models:\n class User < ApplicationRecord\n
242
+ \ include Whodunit::Stampable\n end\n\n\U0001F4D6 Complete documentation: https://kanutocd.github.io/whodunit\n"
238
243
  rdoc_options: []
239
244
  require_paths:
240
245
  - lib