Class: RailsConsolePro::StatsResult

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_console_pro/stats_result.rb

Overview

Value object for model statistics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, record_count:, growth_rate: nil, table_size: nil, index_usage: {}, column_stats: {}, timestamp: Time.current) ⇒ StatsResult

Returns a new instance of StatsResult.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rails_console_pro/stats_result.rb', line 9

def initialize(model:, record_count:, growth_rate: nil, table_size: nil,
               index_usage: {}, column_stats: {}, timestamp: Time.current)
  @model = model
  @record_count = record_count
  @growth_rate = growth_rate
  @table_size = table_size
  @index_usage = index_usage
  @column_stats = column_stats
  @timestamp = timestamp
  validate_model!
end

Instance Attribute Details

#column_statsObject (readonly)

Returns the value of attribute column_stats.



6
7
8
# File 'lib/rails_console_pro/stats_result.rb', line 6

def column_stats
  @column_stats
end

#growth_rateObject (readonly)

Returns the value of attribute growth_rate.



6
7
8
# File 'lib/rails_console_pro/stats_result.rb', line 6

def growth_rate
  @growth_rate
end

#index_usageObject (readonly)

Returns the value of attribute index_usage.



6
7
8
# File 'lib/rails_console_pro/stats_result.rb', line 6

def index_usage
  @index_usage
end

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/rails_console_pro/stats_result.rb', line 6

def model
  @model
end

#record_countObject (readonly)

Returns the value of attribute record_count.



6
7
8
# File 'lib/rails_console_pro/stats_result.rb', line 6

def record_count
  @record_count
end

#table_sizeObject (readonly)

Returns the value of attribute table_size.



6
7
8
# File 'lib/rails_console_pro/stats_result.rb', line 6

def table_size
  @table_size
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/rails_console_pro/stats_result.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/rails_console_pro/stats_result.rb', line 21

def ==(other)
  other.is_a?(self.class) && other.model == model && other.timestamp == timestamp
end

#export_to_file(file_path, format: nil) ⇒ Object

Export to file



53
54
55
# File 'lib/rails_console_pro/stats_result.rb', line 53

def export_to_file(file_path, format: nil)
  FormatExporter.export_to_file(self, file_path, format: format)
end

#has_growth_data?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rails_console_pro/stats_result.rb', line 25

def has_growth_data?
  !growth_rate.nil?
end

#has_index_data?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rails_console_pro/stats_result.rb', line 33

def has_index_data?
  index_usage.any?
end

#has_table_size?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rails_console_pro/stats_result.rb', line 29

def has_table_size?
  !table_size.nil?
end

#to_html(style: :default) ⇒ Object

Export to HTML



48
49
50
# File 'lib/rails_console_pro/stats_result.rb', line 48

def to_html(style: :default)
  FormatExporter.to_html(self, title: "Statistics: #{model.name}", style: style)
end

#to_json(pretty: true) ⇒ Object

Export to JSON



38
39
40
# File 'lib/rails_console_pro/stats_result.rb', line 38

def to_json(pretty: true)
  FormatExporter.to_json(self, pretty: pretty)
end

#to_yamlObject

Export to YAML



43
44
45
# File 'lib/rails_console_pro/stats_result.rb', line 43

def to_yaml
  FormatExporter.to_yaml(self)
end