https://github.com/patrick204nqh/class-metrix
Extracts and compares class behaviors (constants, class methods, and more) across multiple classes, generating clean markdown reports for analysis, documentation, and compliance auditing.
https://github.com/patrick204nqh/class-metrix
metrix ruby
Last synced: 20 days ago
JSON representation
Extracts and compares class behaviors (constants, class methods, and more) across multiple classes, generating clean markdown reports for analysis, documentation, and compliance auditing.
- Host: GitHub
- URL: https://github.com/patrick204nqh/class-metrix
- Owner: patrick204nqh
- License: mit
- Created: 2025-06-07T07:06:49.000Z (26 days ago)
- Default Branch: master
- Last Pushed: 2025-06-07T09:13:55.000Z (26 days ago)
- Last Synced: 2025-06-07T09:17:46.191Z (26 days ago)
- Topics: metrix, ruby
- Language: Ruby
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ClassMetrix
[](https://badge.fury.io/rb/class-metrix)
[](https://github.com/patrick204nqh/class-metrix/actions/workflows/main.yml)
[](https://rubydoc.info/gems/class-metrix)
[](https://qlty.sh/gh/patrick204nqh/projects/class-metrix)
[](https://qlty.sh/gh/patrick204nqh/projects/class-metrix)**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
```ruby
gem 'class-metrix'
```### Basic Usage
```ruby
# 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
```ruby
# 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
```ruby
# 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
```ruby
# 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
```ruby
# Compare authorization policies
ClassMetrix.extract(:constants)
.from([UserPolicy, AdminPolicy, ModeratorPolicy])
.filter(/^PERMISSION_/, /^ROLE_/)
.to_markdown("policy_comparison.md")
```## ๐ Documentation
- **[Examples](examples/)** - Comprehensive usage examples
- **[Configuration Guide](docs/CONFIGURATION.md)** - Detailed configuration options
- **[Architecture](docs/ARCHITECTURE.md)** - Technical architecture overview
- **[Changelog](CHANGELOG.md)** - Version history and changes## ๐งช Development
```bash
# 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](LICENSE.txt).