Class: EvilSeed::Dumper
- Inherits:
-
Object
- Object
- EvilSeed::Dumper
- Defined in:
- lib/evil_seed/dumper.rb
Overview
This class initiates dump creation for every root model of configuration and then concatenates dumps from all roots into one single IO.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#loaded_map ⇒ Object
readonly
Returns the value of attribute loaded_map.
-
#to_load_map ⇒ Object
readonly
Returns the value of attribute to_load_map.
Instance Method Summary collapse
-
#call(output) ⇒ Object
Generate dump for this configuration and write it into provided
io. -
#initialize(configuration) ⇒ Dumper
constructor
A new instance of Dumper.
Constructor Details
#initialize(configuration) ⇒ Dumper
Returns a new instance of Dumper.
13 14 15 |
# File 'lib/evil_seed/dumper.rb', line 13 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
10 11 12 |
# File 'lib/evil_seed/dumper.rb', line 10 def configuration @configuration end |
#loaded_map ⇒ Object (readonly)
Returns the value of attribute loaded_map.
10 11 12 |
# File 'lib/evil_seed/dumper.rb', line 10 def loaded_map @loaded_map end |
#to_load_map ⇒ Object (readonly)
Returns the value of attribute to_load_map.
10 11 12 |
# File 'lib/evil_seed/dumper.rb', line 10 def to_load_map @to_load_map end |
Instance Method Details
#call(output) ⇒ Object
Generate dump for this configuration and write it into provided io
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/evil_seed/dumper.rb', line 19 def call(output) @loaded_map = Hash.new { |h, k| h[k] = Set.new } # stores primary keys of already dumped records for every table @to_load_map = Hash.new { |h, k| h[k] = Set.new } # stores primary keys of records we're going to dump to avoid cycles @output = output configuration.roots.each do |root| table_outputs = RootDumper.new(root, self).call table_outputs.each do |table_dump_io| table_dump_io.rewind IO.copy_stream(table_dump_io, @output) end end ensure @output.close end |