Class: RailsAiBridge::DatabaseSize
- Inherits:
-
Object
- Object
- RailsAiBridge::DatabaseSize
- Defined in:
- lib/rails_ai_bridge/database_size.rb
Overview
Shared utility for mapping approximate database row counts to safe,
human-oriented size bucket labels (+small+, medium, large, hot).
Extracted from Serializers::ContextSummary so that both the introspection
layer and the serializer layer can use it without introspectors depending
on serializers (an ArchSpec boundary violation).
Defined Under Namespace
Classes: BucketLabel
Class Method Summary collapse
-
.bucket(row_count) ⇒ String?
Safe size bucket label.
-
.bucket_for_table(context, table_name) ⇒ String?
Safe size bucket label for the table.
Instance Method Summary collapse
-
#bucket ⇒ String?
Safe size bucket label.
-
#bucket_for_table(table_name) ⇒ String?
Safe size bucket label for the table.
-
#initialize(context) ⇒ DatabaseSize
constructor
A new instance of DatabaseSize.
Constructor Details
#initialize(context) ⇒ DatabaseSize
Returns a new instance of DatabaseSize.
24 25 26 |
# File 'lib/rails_ai_bridge/database_size.rb', line 24 def initialize(context) @context = context end |
Class Method Details
.bucket(row_count) ⇒ String?
Returns safe size bucket label.
13 14 15 |
# File 'lib/rails_ai_bridge/database_size.rb', line 13 def self.bucket(row_count) BucketLabel.new(row_count).label end |
.bucket_for_table(context, table_name) ⇒ String?
Returns safe size bucket label for the table.
20 21 22 |
# File 'lib/rails_ai_bridge/database_size.rb', line 20 def self.bucket_for_table(context, table_name) new(context).bucket_for_table(table_name) end |
Instance Method Details
#bucket ⇒ String?
Returns safe size bucket label.
30 |
# File 'lib/rails_ai_bridge/database_size.rb', line 30 delegate :bucket, to: :class |
#bucket_for_table(table_name) ⇒ String?
Returns safe size bucket label for the table.
34 35 36 37 38 39 40 |
# File 'lib/rails_ai_bridge/database_size.rb', line 34 def bucket_for_table(table_name) table_stats = row_for(table_name.to_s) return unless table_stats stats = table_stats.with_indifferent_access bucket(stats[:size_bucket] || stats[:approximate_rows]) end |