Skip to content

Ruby gem for extracting and analyzing class behaviors (constants, methods, etc.) across multiple classes with clean markdown/CSV reporting. Perfect for code auditing, documentation, and compliance analysis.

License

Notifications You must be signed in to change notification settings

patrick204nqh/class-metrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

63 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ClassMetrix

Gem Version CI Documentation Code Coverage Maintainability

ClassMetrix is a Ruby gem that extracts and compares class behaviors (constants, class methods, and more) across multiple classes, generating clean markdown reports for analysis, documentation, and compliance auditing.

Why "Metrix"? Short for "metrics" - measuring and analyzing class behaviors.

✨ Features

  • πŸ” Multi-Type Extraction: Constants, class methods, and more
  • πŸ—οΈ Comprehensive by Default: Includes inheritance and modules automatically
  • 🎯 Flexible Scanning: Use strict() for class-only or with_private() for private members
  • πŸ“Š Hash Expansion: Expand hash values into readable sub-rows
  • πŸ“ Rich Reports: Professional markdown and CSV output with full configuration
  • πŸ”’ Type Safe: Full RBS type annotations with Steep type checking

πŸš€ Quick Start

Installation

gem 'class-metrix'

Basic Usage

# Extract constants from multiple classes (comprehensive by default)
ClassMetrix.extract(:constants)
  .from([User, Admin, Guest])
  .to_markdown

# Class-only scanning (exclude inheritance & modules)
ClassMetrix.extract(:constants)
  .from([User, Admin, Guest])
  .strict
  .to_markdown

# Advanced example with multiple features
ClassMetrix.extract(:constants, :class_methods)
  .from([DatabaseConfig, RedisConfig, S3Config])
  .with_private
  .filter(/config$/)
  .expand_hashes
  .handle_errors
  .to_markdown("audit_report.md",
    title: "Service Configuration Audit",
    show_missing_summary: true
  )

πŸ“– API Reference

Core Methods

  • .extract(types) - Extract constants, class_methods, or both
  • .from(classes) - Specify which classes to analyze
  • .strict - Class-only scanning (exclude inheritance & modules)
  • .with_private - Include private methods and constants
  • .filter(patterns) - Filter behaviors by regex patterns
  • .expand_hashes - Expand hash values into sub-rows
  • .handle_errors - Graceful error handling
  • .debug(level) - Enable debug logging (:basic, :detailed, :verbose)

Output Formats

# Markdown output
.to_markdown("report.md", title: "Custom Title", footer_style: :detailed)

# CSV output
.to_csv("data.csv", flatten_hashes: true, separator: ";")

🎯 Common Use Cases

Configuration Audit

# Compare configuration across microservices
services = [DatabaseService, RedisService, S3Service]

ClassMetrix.extract(:constants, :class_methods)
  .from(services)
  .filter(/CONFIG/, /timeout/)
  .expand_hashes
  .to_markdown("microservices_audit.md")

API Compatibility Check

# Check API compatibility across versions
apis = [V1::UsersAPI, V2::UsersAPI, V3::UsersAPI]

ClassMetrix.extract(:class_methods)
  .from(apis)
  .filter(/^endpoint_/, /^validate_/)
  .handle_errors
  .to_markdown("api_compatibility.md", show_missing_summary: true)

Policy Comparison

# Compare authorization policies
ClassMetrix.extract(:constants)
  .from([UserPolicy, AdminPolicy, ModeratorPolicy])
  .filter(/^PERMISSION_/, /^ROLE_/)
  .to_markdown("policy_comparison.md")

πŸ“š Documentation

πŸ§ͺ Development

# Clone and setup
git clone https://github.com/patrick204nqh/class-metrix.git
cd class-metrix
bundle install

# Run tests and type checking
bundle exec rspec
bundle exec steep check
bundle exec rubocop

πŸ“‹ Requirements

  • Ruby 3.1+ (Required for full RBS and Steep support)
  • No runtime dependencies (Pure Ruby implementation)

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -am 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This gem is available as open source under the terms of the MIT License.

About

Ruby gem for extracting and analyzing class behaviors (constants, methods, etc.) across multiple classes with clean markdown/CSV reporting. Perfect for code auditing, documentation, and compliance analysis.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •