require 'flydata/source' require 'flydata/source/component' require 'flydata/source/errors' module Flydata module Source class GenerateSourceDump < Component def self.inherited(child_class) Source.register(child_class, self) end def initialize(source, dp, options) super(source, options) @dp = dp end attr_reader :dp # Public Interface: Run compatibility check # # Run whatever check (compatibility, connectivity, privilege, etc) to ensure # that initial sync can run without an issue. # # dump_dir: A directory path string to the dump directory # backup_dir: A directory path string to the backup directory # # Raises exception when check fails def run_compatibility_check(dump_dir, backup_dir) raise UnsupportedSourceError, "subclass must implement" end # Public Interface: Confirmation items # # Returns a hash of items to be shown as the final confirmation before # initial sync. # Example: Return value {"host" => "ubertas","port" => 3306} # will be displayed as # host: ubertas # port: 3306 def confirmation_items raise UnsupportedSourceError, "subclass must implement" end # Public Interface: Dump size # # tables: An array of table names to be dumped. # # Returns an approximate size of dump in bytes. The value may be a # best-effort estimate. It doesn't have to be accurate. def dump_size(tables) raise UnsupportedSourceError, "subclass must implement" end # Public Interface: Dump data # # tables: An array of tables to be dumped. # file_path: A file path string of the dump file to which data is written. # This value may be nil, in which case contents are written to a # pipe. # src_pos_callback: A callback called when the source position of the dump # becomes available. The callback takes the following arguments. # io: Input IO to the dump. # src_pos: Source position of the dump # # Returns none def dump(tables, file_path = nil, &src_pos_callback) raise UnsupportedSourceError, "subclass must implement" end end end end