Top Level Namespace

Defined Under Namespace

Modules: Transfer

Instance Method Summary collapse

Instance Method Details

#transfer(*args, &block) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/transfer.rb', line 28

def transfer *args, &block
  raise ArgumentError if args.length == 0

  case args[0]
  when Symbol, String
    args[0] = Transfer.configs[args[0].to_sym]
    transfer *args, &block
  when Hash
    transfer :default, *args, &block
  when Transfer::Config
    raise ArgumentError.new("second argument should be Hash!") unless args[1].instance_of?(Hash)
    config, options = args[0], args[1]
    process_keys = [:validate, :failure_strategy]
    process_options = config.process_options.merge options.select{|key| process_keys.include?(key) }
    sources = options.select{|key| !process_keys.include?(key) }
    sources.each do |key, value|
      dataset = config.connection[key]
      transferer = Transfer::Transferer.new dataset, value, &block
      transferer.process process_options
    end
  end

end