Class: EvilSeed::Dumper

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Dumper

Returns a new instance of Dumper.

Parameters:



13
14
15
# File 'lib/evil_seed/dumper.rb', line 13

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



10
11
12
# File 'lib/evil_seed/dumper.rb', line 10

def configuration
  @configuration
end

#loaded_mapObject (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

Instance Method Details

#call(output) ⇒ Object

Generate dump for this configuration and write it into provided io

Parameters:

  • output (IO)

    Stream to write SQL dump into



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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
  @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