π Gem Activity Tracker
gem_activity_tracker is a Ruby gem that tracks the internal structure, changes, and metadata of your Ruby or Rails projects. It generates a complete project activity report in YAML, with support for JSON/CSV export, auto-tracking with file watcher, and Git log visualization.
π Features
- π Analyze project structure: models, controllers, jobs, services, mailers, routes, etc.
- π§ Advanced model analysis: attributes, associations, methods, validations, callbacks, and enums.
- ποΈ Migration tracking and schema hashing.
- π οΈ Detect database type from
database.yml. - π¦ Git history tracking (last 20 commits).
- π Auto-tracking using the
listengem on file changes. - π Export report to YAML, JSON, or CSV.
- β Works with both Rails and plain Ruby projects.
π¦ Installation
Add this line to your application's Gemfile:
gem 'gem_activity_tracker'
Then run:
bundle install
Or install it directly:
gem install gem_activity_tracker
βοΈ Usage
π Basic CLI Commands
gem_activity_tracker --track=PATH # Track a Ruby/Rails project and generate report
gem_activity_tracker --report # Show last generated report
gem_activity_tracker --export=json # Export report to JSON
gem_activity_tracker --export=csv # Export report to CSV
gem_activity_tracker --watch # Start file watcher to auto-track changes
π οΈ Rails Auto-Tracking
In a Rails app, the gem automatically hooks into the app after initialization via a Railtie.
Set this in your .env or shell:
export GEM_ACTIVITY_TRACKER_ENABLED=true
Then start your Rails app and the gem will:
- Detect and track changes
- Update
activity_tracker/report.yml - Start watching the file system
π Output
The gem creates an activity_tracker/ folder at your project root:
activity_tracker/
βββ report.yml # Main YAML report
βββ report.json # (Optional) Exported JSON
βββ report.csv # (Optional) Exported CSV
βββ log.txt # File change logs (when watch mode is on)
π Whatβs Tracked?
| Component | Details |
|---|---|
| Models | Count, files, attributes, associations, methods, validations, enums |
| Controllers | List of files |
| Services | List of files |
| Mailers | List of files |
| Jobs | List of files |
| Migrations | Count and recent migration names |
| Routes | Full route listing via rails routes |
| Schema | Schema hash (db/schema.rb) |
| Git Log | Last 20 commits |
| Database | Type detected from config/database.yml |
π Auto-Watcher
Auto-track changes in real-time using the listen gem:
gem_activity_tracker --watch
You'll see logs like:
[2025-04-10 12:00:00] Modified: app/models/user.rb
[2025-04-10 12:00:01] Added: app/services/new_service.rb
Each change triggers regeneration of the report.
π§ͺ Example Output (YAML)
ruby_version: ruby 3.2.2
rails_version: 6.1.4
database: postgresql
models:
count: 5
files:
- app/models/user.rb
- app/models/post.rb
detailed:
User:
table_name: users
attributes: [id, name, email]
associations:
has_many: [posts]
validations: ["PresenceValidator"]
callbacks: [before_create, after_save]
controllers:
count: 3
files: [...]
git_log:
- "1a2b3c4 - Atul Yadav (2025-04-10): Add model tracker"
- ...
π‘ Configuration
You can toggle auto-tracking with an ENV variable:
export GEM_ACTIVITY_TRACKER_ENABLED=false # disables auto-tracking
π§ Author
Atul Yadav
π§ [email protected]
π Indore, India
π LinkedIn
π¦ RubyGems: gem_activity_tracker
π License
This project is licensed under the MIT License. See LICENSE.txt for details.
π¬ Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.