Class: FuryDumper::Dumpers::DumpState
- Inherits:
-
Object
- Object
- FuryDumper::Dumpers::DumpState
- Defined in:
- lib/fury_dumper/dumpers/dump_state.rb
Instance Attribute Summary collapse
-
#batch ⇒ Object
Returns the value of attribute batch.
-
#iteration ⇒ Object
Returns the value of attribute iteration.
-
#loaded_relations ⇒ Object
Returns the value of attribute loaded_relations.
-
#root_source_model ⇒ Object
Returns the value of attribute root_source_model.
Instance Method Summary collapse
- #add_loaded_relation(new_relation) ⇒ Object
- #include_relation?(relation_name) ⇒ Boolean
-
#initialize(root_source_model:, loaded_relations: []) ⇒ DumpState
constructor
A new instance of DumpState.
- #print_statistic ⇒ Object
- #stop ⇒ Object
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
#batch ⇒ Object
Returns the value of attribute batch.
6 7 8 |
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 6 def batch @batch end |
#iteration ⇒ Object
Returns the value of attribute iteration.
6 7 8 |
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 6 def iteration @iteration end |
#loaded_relations ⇒ Object
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_model ⇒ Object
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
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
18 19 20 |
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 18 def include_relation?(relation_name) loaded_relations.include?(relation_name) end |
#print_statistic ⇒ Object
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 |
#stop ⇒ Object
14 15 16 |
# File 'lib/fury_dumper/dumpers/dump_state.rb', line 14 def stop @end_time = Time.current end |