class-metrix 0.1.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.editorconfig +48 -0
- data/.vscode/README.md +72 -0
- data/.vscode/extensions.json +28 -0
- data/.vscode/launch.json +32 -0
- data/.vscode/settings.json +88 -0
- data/.vscode/tasks.json +99 -0
- data/CHANGELOG.md +71 -4
- data/README.md +41 -7
- data/docs/ARCHITECTURE.md +501 -0
- data/examples/README.md +161 -114
- data/examples/basic_usage.rb +88 -0
- data/examples/debug_levels_demo.rb +65 -0
- data/examples/debug_mode_demo.rb +75 -0
- data/examples/inheritance_and_modules.rb +155 -0
- data/lib/class_metrix/extractor.rb +106 -11
- data/lib/class_metrix/extractors/constants_extractor.rb +155 -21
- data/lib/class_metrix/extractors/methods_extractor.rb +186 -21
- data/lib/class_metrix/extractors/multi_type_extractor.rb +6 -5
- data/lib/class_metrix/formatters/components/footer_component.rb +1 -1
- data/lib/class_metrix/formatters/components/table_component/column_width_calculator.rb +56 -0
- data/lib/class_metrix/formatters/components/table_component/row_processor.rb +138 -0
- data/lib/class_metrix/formatters/components/table_component/table_data_extractor.rb +54 -0
- data/lib/class_metrix/formatters/components/table_component/table_renderer.rb +55 -0
- data/lib/class_metrix/formatters/components/table_component.rb +30 -244
- data/lib/class_metrix/formatters/shared/markdown_table_builder.rb +10 -5
- data/lib/class_metrix/formatters/shared/table_builder.rb +84 -21
- data/lib/class_metrix/formatters/shared/value_processor.rb +72 -16
- data/lib/class_metrix/utils/debug_logger.rb +159 -0
- data/lib/class_metrix/version.rb +1 -1
- metadata +17 -9
- data/examples/advanced/error_handling.rb +0 -199
- data/examples/advanced/hash_expansion.rb +0 -180
- data/examples/basic/01_simple_constants.rb +0 -56
- data/examples/basic/02_simple_methods.rb +0 -99
- data/examples/basic/03_multi_type_extraction.rb +0 -116
- data/examples/components/configurable_reports.rb +0 -201
- data/examples/csv_output_demo.rb +0 -237
- data/examples/real_world/microservices_audit.rb +0 -312
@@ -1,99 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative "../../lib/class_metrix"
|
5
|
-
|
6
|
-
puts "=== Basic Example 2: Simple Class Methods ==="
|
7
|
-
puts
|
8
|
-
|
9
|
-
# Define some simple classes with class methods
|
10
|
-
class PaymentProcessor
|
11
|
-
def self.supported_currencies
|
12
|
-
%w[USD EUR GBP]
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.max_amount
|
16
|
-
10_000
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.requires_verification?
|
20
|
-
false
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.processing_fee
|
24
|
-
2.5
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class StripeProcessor
|
29
|
-
def self.supported_currencies
|
30
|
-
%w[USD EUR GBP CAD AUD]
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.max_amount
|
34
|
-
50_000
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.requires_verification?
|
38
|
-
true
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.processing_fee
|
42
|
-
2.9
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.supports_recurring?
|
46
|
-
true
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class PayPalProcessor
|
51
|
-
def self.supported_currencies
|
52
|
-
%w[USD EUR]
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.max_amount
|
56
|
-
25_000
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.requires_verification?
|
60
|
-
true
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.processing_fee
|
64
|
-
3.4
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.instant_transfer?
|
68
|
-
false
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
puts "Classes defined: PaymentProcessor, StripeProcessor, PayPalProcessor"
|
73
|
-
puts "Methods: supported_currencies, max_amount, requires_verification?, processing_fee, etc."
|
74
|
-
puts
|
75
|
-
|
76
|
-
# Extract all class methods
|
77
|
-
puts "📋 All Class Methods:"
|
78
|
-
puts ClassMetrix.extract(:class_methods)
|
79
|
-
.from([PaymentProcessor, StripeProcessor, PayPalProcessor])
|
80
|
-
.to_markdown
|
81
|
-
puts
|
82
|
-
|
83
|
-
# Extract boolean methods only
|
84
|
-
puts "✅ Boolean Methods (ending with ?):"
|
85
|
-
puts ClassMetrix.extract(:class_methods)
|
86
|
-
.from([PaymentProcessor, StripeProcessor, PayPalProcessor])
|
87
|
-
.filter(/\?$/)
|
88
|
-
.to_markdown
|
89
|
-
puts
|
90
|
-
|
91
|
-
# Extract configuration methods
|
92
|
-
puts "⚙️ Configuration Methods (max, fee, supported):"
|
93
|
-
puts ClassMetrix.extract(:class_methods)
|
94
|
-
.from([PaymentProcessor, StripeProcessor, PayPalProcessor])
|
95
|
-
.filter(/max|fee|supported/)
|
96
|
-
.to_markdown
|
97
|
-
puts
|
98
|
-
|
99
|
-
puts "✨ This example shows class method extraction with different return types!"
|
@@ -1,116 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative "../../lib/class_metrix"
|
5
|
-
|
6
|
-
puts "=== Basic Example 3: Multi-Type Extraction ==="
|
7
|
-
puts
|
8
|
-
|
9
|
-
# Define classes with both constants and methods
|
10
|
-
class EmailService
|
11
|
-
# Constants
|
12
|
-
PROVIDER_NAME = "smtp"
|
13
|
-
DEFAULT_PORT = 587
|
14
|
-
ENCRYPTION_ENABLED = true
|
15
|
-
|
16
|
-
# Class methods
|
17
|
-
def self.provider_name
|
18
|
-
"SMTP Service"
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.default_port
|
22
|
-
587
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.encryption_enabled?
|
26
|
-
true
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.rate_limit
|
30
|
-
100
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class SendGridService
|
35
|
-
# Constants
|
36
|
-
PROVIDER_NAME = "sendgrid"
|
37
|
-
DEFAULT_PORT = 443
|
38
|
-
ENCRYPTION_ENABLED = true
|
39
|
-
API_VERSION = "v3"
|
40
|
-
|
41
|
-
# Class methods
|
42
|
-
def self.provider_name
|
43
|
-
"SendGrid API"
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.default_port
|
47
|
-
443
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.encryption_enabled?
|
51
|
-
true
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.rate_limit
|
55
|
-
1000
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.api_version
|
59
|
-
"v3"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class MailgunService
|
64
|
-
# Constants
|
65
|
-
PROVIDER_NAME = "mailgun"
|
66
|
-
DEFAULT_PORT = 443
|
67
|
-
ENCRYPTION_ENABLED = true
|
68
|
-
|
69
|
-
# Class methods
|
70
|
-
def self.provider_name
|
71
|
-
"Mailgun API"
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.default_port
|
75
|
-
443
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.encryption_enabled?
|
79
|
-
true
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.rate_limit
|
83
|
-
500
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
puts "Classes defined: EmailService, SendGridService, MailgunService"
|
88
|
-
puts "Each has constants AND class methods with similar names"
|
89
|
-
puts
|
90
|
-
|
91
|
-
# Compare constants vs methods
|
92
|
-
puts "📊 Multi-Type Extraction (Constants + Methods):"
|
93
|
-
puts ClassMetrix.extract(:constants, :class_methods)
|
94
|
-
.from([EmailService, SendGridService, MailgunService])
|
95
|
-
.filter(/provider_name|default_port|encryption/)
|
96
|
-
.to_markdown
|
97
|
-
puts
|
98
|
-
|
99
|
-
# Compare specific behaviors
|
100
|
-
puts "🎯 Rate Limiting Comparison:"
|
101
|
-
puts ClassMetrix.extract(:constants, :class_methods)
|
102
|
-
.from([EmailService, SendGridService, MailgunService])
|
103
|
-
.filter(/rate_limit/)
|
104
|
-
.to_markdown
|
105
|
-
puts
|
106
|
-
|
107
|
-
# API-specific features
|
108
|
-
puts "🔌 API Features:"
|
109
|
-
puts ClassMetrix.extract(:constants, :class_methods)
|
110
|
-
.from([EmailService, SendGridService, MailgunService])
|
111
|
-
.filter(/API|version/)
|
112
|
-
.to_markdown
|
113
|
-
puts
|
114
|
-
|
115
|
-
puts "✨ This example shows how to compare both constants and methods in one table!"
|
116
|
-
puts "Notice how the 'Type' column distinguishes between constants and methods."
|
@@ -1,201 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative "../../lib/class_metrix"
|
5
|
-
|
6
|
-
# Example classes for demonstration
|
7
|
-
class DatabaseService
|
8
|
-
DEFAULT_CONFIG = { host: "localhost", port: 5432, ssl: true }.freeze
|
9
|
-
TIMEOUT_CONFIG = { connect: 30, read: 60, write: 30 }.freeze
|
10
|
-
|
11
|
-
def self.connection_timeout
|
12
|
-
30
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.pool_size
|
16
|
-
10
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class RedisService
|
21
|
-
DEFAULT_CONFIG = { host: "redis.local", port: 6379, ssl: false }.freeze
|
22
|
-
CLUSTER_CONFIG = { nodes: 3, replication: true, sharding: "consistent" }.freeze
|
23
|
-
|
24
|
-
def self.connection_timeout
|
25
|
-
5
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.pool_size
|
29
|
-
20
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class S3Service
|
34
|
-
DEFAULT_CONFIG = { region: "us-east-1", bucket: "my-bucket" }.freeze
|
35
|
-
|
36
|
-
def self.connection_timeout
|
37
|
-
60
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
puts "=" * 80
|
42
|
-
puts "ClassMetrix v2.0 - Configurable Component Examples"
|
43
|
-
puts "=" * 80
|
44
|
-
|
45
|
-
# Example 1: Minimal Report (table only)
|
46
|
-
puts "\n1. MINIMAL REPORT (table only)"
|
47
|
-
puts "-" * 40
|
48
|
-
|
49
|
-
minimal = ClassMetrix.extract(:constants)
|
50
|
-
.from([DatabaseService, RedisService, S3Service])
|
51
|
-
.filter(/DEFAULT_CONFIG/)
|
52
|
-
.to_markdown(
|
53
|
-
show_metadata: false,
|
54
|
-
show_classes: false,
|
55
|
-
show_extraction_info: false,
|
56
|
-
show_footer: false
|
57
|
-
)
|
58
|
-
|
59
|
-
puts minimal
|
60
|
-
|
61
|
-
# Example 2: Standard Report with Custom Title
|
62
|
-
puts "\n2. STANDARD REPORT with custom title"
|
63
|
-
puts "-" * 40
|
64
|
-
|
65
|
-
standard = ClassMetrix.extract(:constants, :class_methods)
|
66
|
-
.from([DatabaseService, RedisService, S3Service])
|
67
|
-
.filter(/CONFIG|timeout/)
|
68
|
-
.expand_hashes
|
69
|
-
.handle_errors
|
70
|
-
.to_markdown(
|
71
|
-
title: "Microservices Configuration Analysis"
|
72
|
-
)
|
73
|
-
|
74
|
-
puts standard
|
75
|
-
|
76
|
-
# Example 3: Detailed Report with All Features
|
77
|
-
puts "\n3. DETAILED REPORT with all features"
|
78
|
-
puts "-" * 40
|
79
|
-
|
80
|
-
detailed = ClassMetrix.extract(:constants, :class_methods)
|
81
|
-
.from([DatabaseService, RedisService, S3Service])
|
82
|
-
.filter(/CONFIG|timeout|pool/)
|
83
|
-
.expand_hashes
|
84
|
-
.handle_errors
|
85
|
-
.to_markdown(
|
86
|
-
title: "Complete Service Analysis",
|
87
|
-
show_missing_summary: true,
|
88
|
-
summary_style: :detailed,
|
89
|
-
footer_style: :detailed,
|
90
|
-
show_timestamp: true,
|
91
|
-
custom_footer: "Generated for production deployment review"
|
92
|
-
)
|
93
|
-
|
94
|
-
puts detailed
|
95
|
-
|
96
|
-
# Example 4: Compact Table Style
|
97
|
-
puts "\n4. COMPACT TABLE STYLE"
|
98
|
-
puts "-" * 40
|
99
|
-
|
100
|
-
compact = ClassMetrix.extract(:class_methods)
|
101
|
-
.from([DatabaseService, RedisService, S3Service])
|
102
|
-
.filter(/timeout|pool/)
|
103
|
-
.to_markdown(
|
104
|
-
title: "Service Performance Settings",
|
105
|
-
table_style: :compact,
|
106
|
-
max_column_width: 20,
|
107
|
-
footer_style: :minimal
|
108
|
-
)
|
109
|
-
|
110
|
-
puts compact
|
111
|
-
|
112
|
-
# Example 5: Different Summary Styles
|
113
|
-
puts "\n5. DIFFERENT SUMMARY STYLES"
|
114
|
-
puts "-" * 40
|
115
|
-
|
116
|
-
# Flat summary style
|
117
|
-
flat_summary = ClassMetrix.extract(:constants)
|
118
|
-
.from([DatabaseService, RedisService, S3Service])
|
119
|
-
.filter(/CLUSTER|TIMEOUT/)
|
120
|
-
.handle_errors
|
121
|
-
.to_markdown(
|
122
|
-
title: "Missing Configurations (Flat Style)",
|
123
|
-
show_missing_summary: true,
|
124
|
-
summary_style: :flat,
|
125
|
-
show_classes: false,
|
126
|
-
show_extraction_info: false
|
127
|
-
)
|
128
|
-
|
129
|
-
puts flat_summary
|
130
|
-
|
131
|
-
# Example 6: Save Different Formats to Files
|
132
|
-
puts "\n6. SAVING REPORTS TO FILES"
|
133
|
-
puts "-" * 40
|
134
|
-
|
135
|
-
# Save minimal report
|
136
|
-
ClassMetrix.extract(:constants)
|
137
|
-
.from([DatabaseService, RedisService, S3Service])
|
138
|
-
.filter(/DEFAULT_CONFIG/)
|
139
|
-
.expand_hashes
|
140
|
-
.to_markdown("reports/minimal_config.md",
|
141
|
-
title: "Service Default Configurations",
|
142
|
-
show_missing_summary: false,
|
143
|
-
footer_style: :minimal)
|
144
|
-
|
145
|
-
# Save detailed audit report
|
146
|
-
ClassMetrix.extract(:constants, :class_methods)
|
147
|
-
.from([DatabaseService, RedisService, S3Service])
|
148
|
-
.filter(/CONFIG|timeout|pool/)
|
149
|
-
.expand_hashes
|
150
|
-
.handle_errors
|
151
|
-
.to_markdown("reports/detailed_audit.md",
|
152
|
-
title: "Complete Microservices Audit",
|
153
|
-
show_missing_summary: true,
|
154
|
-
summary_style: :detailed,
|
155
|
-
footer_style: :detailed,
|
156
|
-
show_timestamp: true,
|
157
|
-
custom_footer: "Audit performed for compliance review")
|
158
|
-
|
159
|
-
# Save compact performance report
|
160
|
-
ClassMetrix.extract(:class_methods)
|
161
|
-
.from([DatabaseService, RedisService, S3Service])
|
162
|
-
.filter(/timeout|pool/)
|
163
|
-
.to_markdown("reports/performance_settings.md",
|
164
|
-
title: "Service Performance Configuration",
|
165
|
-
table_style: :compact,
|
166
|
-
max_column_width: 25,
|
167
|
-
show_classes: true,
|
168
|
-
show_extraction_info: false,
|
169
|
-
footer_style: :default)
|
170
|
-
|
171
|
-
puts "✅ Reports saved to:"
|
172
|
-
puts " - reports/minimal_config.md"
|
173
|
-
puts " - reports/detailed_audit.md"
|
174
|
-
puts " - reports/performance_settings.md"
|
175
|
-
|
176
|
-
puts "\n#{"=" * 80}"
|
177
|
-
puts "Component Configuration Summary:"
|
178
|
-
puts "=" * 80
|
179
|
-
puts "✨ Header Component Options:"
|
180
|
-
puts " - title: Custom report title"
|
181
|
-
puts " - show_metadata: Show/hide title section"
|
182
|
-
puts " - show_classes: Show/hide classes analyzed section"
|
183
|
-
puts " - show_extraction_info: Show/hide extraction types section"
|
184
|
-
puts ""
|
185
|
-
puts "📊 Table Component Options:"
|
186
|
-
puts " - table_style: :standard, :compact, :wide"
|
187
|
-
puts " - min_column_width: Minimum column width"
|
188
|
-
puts " - max_column_width: Maximum column width (for compact style)"
|
189
|
-
puts ""
|
190
|
-
puts "📋 Missing Behaviors Component Options:"
|
191
|
-
puts " - show_missing_summary: Show/hide missing behaviors analysis"
|
192
|
-
puts " - summary_style: :grouped, :flat, :detailed"
|
193
|
-
puts ""
|
194
|
-
puts "📄 Footer Component Options:"
|
195
|
-
puts " - show_footer: Show/hide footer"
|
196
|
-
puts " - footer_style: :default, :minimal, :detailed"
|
197
|
-
puts " - show_timestamp: Include generation timestamp"
|
198
|
-
puts " - custom_footer: Custom footer message"
|
199
|
-
puts ""
|
200
|
-
puts "🎯 All components are independently configurable!"
|
201
|
-
puts "=" * 80
|
data/examples/csv_output_demo.rb
DELETED
@@ -1,237 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative "../lib/class_metrix"
|
5
|
-
|
6
|
-
# Example classes for demonstration
|
7
|
-
class DatabaseConfig
|
8
|
-
DEFAULT_CONFIG = {
|
9
|
-
host: "localhost",
|
10
|
-
port: 5432,
|
11
|
-
ssl: true,
|
12
|
-
timeout: 30
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
CLUSTER_CONFIG = {
|
16
|
-
nodes: 3,
|
17
|
-
replication: true
|
18
|
-
}.freeze
|
19
|
-
|
20
|
-
def self.connection_timeout
|
21
|
-
30
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.max_connections
|
25
|
-
100
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class RedisConfig
|
30
|
-
DEFAULT_CONFIG = {
|
31
|
-
host: "redis.local",
|
32
|
-
port: 6379,
|
33
|
-
ssl: false,
|
34
|
-
timeout: 5
|
35
|
-
}.freeze
|
36
|
-
|
37
|
-
CACHE_CONFIG = {
|
38
|
-
ttl: 3600,
|
39
|
-
max_memory: "1GB"
|
40
|
-
}.freeze
|
41
|
-
|
42
|
-
def self.connection_timeout
|
43
|
-
5
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.max_connections
|
47
|
-
50
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class S3Config
|
52
|
-
DEFAULT_CONFIG = {
|
53
|
-
region: "us-east-1",
|
54
|
-
ssl: true,
|
55
|
-
timeout: 60
|
56
|
-
}.freeze
|
57
|
-
|
58
|
-
BUCKET_CONFIG = {
|
59
|
-
versioning: true,
|
60
|
-
encryption: "AES256"
|
61
|
-
}.freeze
|
62
|
-
|
63
|
-
def self.connection_timeout
|
64
|
-
60
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.max_connections
|
68
|
-
25
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
puts "=" * 80
|
73
|
-
puts "ClassMetrix CSV Output Examples"
|
74
|
-
puts "=" * 80
|
75
|
-
|
76
|
-
# Example 1: Simple CSV output
|
77
|
-
puts "\n1. Simple CSV Output (Constants)"
|
78
|
-
puts "-" * 40
|
79
|
-
|
80
|
-
result = ClassMetrix.extract(:constants)
|
81
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
82
|
-
.filter(/DEFAULT_CONFIG/)
|
83
|
-
.to_csv(show_metadata: false)
|
84
|
-
|
85
|
-
puts result
|
86
|
-
|
87
|
-
# Example 2: CSV with metadata
|
88
|
-
puts "\n\n2. CSV with Metadata and Title"
|
89
|
-
puts "-" * 40
|
90
|
-
|
91
|
-
result = ClassMetrix.extract(:constants)
|
92
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
93
|
-
.filter(/DEFAULT_CONFIG/)
|
94
|
-
.to_csv(title: "Service Configuration Comparison")
|
95
|
-
|
96
|
-
puts result
|
97
|
-
|
98
|
-
# Example 3: Multi-type extraction with hash flattening
|
99
|
-
puts "\n\n3. Multi-Type with Hash Flattening"
|
100
|
-
puts "-" * 40
|
101
|
-
|
102
|
-
result = ClassMetrix.extract(:constants, :class_methods)
|
103
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
104
|
-
.filter(/CONFIG|timeout|connections/)
|
105
|
-
.expand_hashes
|
106
|
-
.handle_errors
|
107
|
-
.to_csv(
|
108
|
-
title: "Complete Service Analysis",
|
109
|
-
flatten_hashes: true,
|
110
|
-
show_metadata: true
|
111
|
-
)
|
112
|
-
|
113
|
-
puts result
|
114
|
-
|
115
|
-
# Example 4: Hash expansion with sub-rows (non-flattened)
|
116
|
-
puts "\n\n4. Hash Expansion with Sub-Rows"
|
117
|
-
puts "-" * 40
|
118
|
-
|
119
|
-
result = ClassMetrix.extract(:constants)
|
120
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
121
|
-
.filter(/DEFAULT_CONFIG/)
|
122
|
-
.expand_hashes
|
123
|
-
.to_csv(
|
124
|
-
title: "Configuration Details",
|
125
|
-
flatten_hashes: false,
|
126
|
-
show_metadata: false
|
127
|
-
)
|
128
|
-
|
129
|
-
puts result
|
130
|
-
|
131
|
-
# Example 5: Different CSV separators
|
132
|
-
puts "\n\n5. Semicolon-Separated Values"
|
133
|
-
puts "-" * 40
|
134
|
-
|
135
|
-
result = ClassMetrix.extract(:class_methods)
|
136
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
137
|
-
.filter(/timeout|connections/)
|
138
|
-
.to_csv(
|
139
|
-
separator: ";",
|
140
|
-
show_metadata: false
|
141
|
-
)
|
142
|
-
|
143
|
-
puts result
|
144
|
-
|
145
|
-
# Example 6: Tab-separated values
|
146
|
-
puts "\n\n6. Tab-Separated Values"
|
147
|
-
puts "-" * 40
|
148
|
-
|
149
|
-
result = ClassMetrix.extract(:class_methods)
|
150
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
151
|
-
.filter(/timeout/)
|
152
|
-
.to_csv(
|
153
|
-
separator: "\t",
|
154
|
-
show_metadata: false
|
155
|
-
)
|
156
|
-
|
157
|
-
puts result
|
158
|
-
|
159
|
-
# Example 7: Custom null values
|
160
|
-
puts "\n\n7. Custom Null Values"
|
161
|
-
puts "-" * 40
|
162
|
-
|
163
|
-
result = ClassMetrix.extract(:constants)
|
164
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
165
|
-
.filter(/CLUSTER_CONFIG|CACHE_CONFIG|BUCKET_CONFIG/)
|
166
|
-
.handle_errors
|
167
|
-
.to_csv(
|
168
|
-
null_value: "N/A",
|
169
|
-
show_metadata: false
|
170
|
-
)
|
171
|
-
|
172
|
-
puts result
|
173
|
-
|
174
|
-
# Example 8: Save to file
|
175
|
-
puts "\n\n8. Saving to File"
|
176
|
-
puts "-" * 40
|
177
|
-
|
178
|
-
filename = "service_analysis.csv"
|
179
|
-
ClassMetrix.extract(:constants, :class_methods)
|
180
|
-
.from([DatabaseConfig, RedisConfig, S3Config])
|
181
|
-
.filter(/CONFIG|timeout/)
|
182
|
-
.expand_hashes
|
183
|
-
.handle_errors
|
184
|
-
.to_csv(
|
185
|
-
filename,
|
186
|
-
title: "Service Configuration Analysis",
|
187
|
-
flatten_hashes: true
|
188
|
-
)
|
189
|
-
|
190
|
-
puts "CSV report saved to: #{filename}"
|
191
|
-
puts "File size: #{File.size(filename)} bytes"
|
192
|
-
puts "\nFirst few lines of the file:"
|
193
|
-
puts File.readlines(filename)[0..5].join
|
194
|
-
|
195
|
-
# Example 9: Error handling demonstration
|
196
|
-
puts "\n\n9. Error Handling in CSV"
|
197
|
-
puts "-" * 40
|
198
|
-
|
199
|
-
class BrokenConfig
|
200
|
-
VALID_CONFIG = { host: "localhost" }.freeze
|
201
|
-
|
202
|
-
def self.working_method
|
203
|
-
"success"
|
204
|
-
end
|
205
|
-
|
206
|
-
def self.broken_method
|
207
|
-
raise StandardError, "Something went wrong"
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
result = ClassMetrix.extract(:constants, :class_methods)
|
212
|
-
.from([DatabaseConfig, BrokenConfig])
|
213
|
-
.filter(/CONFIG|method/)
|
214
|
-
.handle_errors
|
215
|
-
.to_csv(show_metadata: false)
|
216
|
-
|
217
|
-
puts result
|
218
|
-
|
219
|
-
puts "\n#{"=" * 80}"
|
220
|
-
puts "CSV Output Features Summary:"
|
221
|
-
puts "=" * 80
|
222
|
-
puts "✓ Simple CSV tables with comma separation"
|
223
|
-
puts "✓ Custom separators (semicolon, tab, etc.)"
|
224
|
-
puts "✓ Metadata headers with comments"
|
225
|
-
puts "✓ Hash flattening into separate columns"
|
226
|
-
puts "✓ Hash expansion into sub-rows"
|
227
|
-
puts "✓ Multi-type extraction support"
|
228
|
-
puts "✓ Error handling with clean output"
|
229
|
-
puts "✓ Custom null value representation"
|
230
|
-
puts "✓ File output capability"
|
231
|
-
puts "✓ Emoji cleaning for CSV compatibility"
|
232
|
-
puts "✓ Boolean value conversion (TRUE/FALSE)"
|
233
|
-
puts "✓ Array value joining with semicolons"
|
234
|
-
puts "=" * 80
|
235
|
-
|
236
|
-
# Clean up
|
237
|
-
File.delete(filename) if File.exist?(filename)
|