πŸ“Š 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 listen gem 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.