Class: FuryDumper::Dumpers::DumpState

Inherits:
Object
  • Object
show all
Defined in:
lib/fury_dumper/dumpers/dump_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_source_model:, loaded_relations: []) ⇒ DumpState

Returns a new instance of DumpState.



8
9
10
11
12
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 8

def initialize(root_source_model:, loaded_relations: [])
  @root_source_model  = root_source_model
  @loaded_relations   = loaded_relations
  @start_time         = Time.current
end

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



6
7
8
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 6

def batch
  @batch
end

#iterationObject

Returns the value of attribute iteration.



6
7
8
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 6

def iteration
  @iteration
end

#loaded_relationsObject

Returns the value of attribute loaded_relations.



6
7
8
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 6

def loaded_relations
  @loaded_relations
end

#root_source_modelObject

Returns the value of attribute root_source_model.



6
7
8
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 6

def root_source_model
  @root_source_model
end

Instance Method Details

#add_loaded_relation(new_relation) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 22

def add_loaded_relation(new_relation)
  raise ArgumentError unless new_relation.is_a?(Model)

  loaded_relations << new_relation unless include_relation?(new_relation)
end

#include_relation?(relation_name) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 18

def include_relation?(relation_name)
  loaded_relations.include?(relation_name)
end


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 28

def print_statistic
  p "📈 Statistic for #{@root_source_model} dump"
  p "Execution time: #{duration}"
  p "Loaded #{@loaded_relations.count} relations"
  p "Loaded #{@loaded_relations.map(&:source_model).uniq.count} uniq models"

  p 'Most repeatable models relations:'
  res = @loaded_relations.group_by(&:source_model).sort_by do |_k, v|
    v.count
  end
  res.last(10).each { |k, v| p "  #{k}: #{v.count} times" }
end

#stopObject



14
15
16
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 14

def stop
  @end_time = Time.current
end