0.0
The project is in a healthy, maintained state
ClassMetrix allows you to easily extract and compare constants and class methods across multiple Ruby classes, generating clean markdown tables for analysis and documentation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 3.0
~> 3.0
~> 1.0
~> 1.0
~> 7.0
~> 0.22
 Project Readme

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.