Class: DataDuck::Destination

Inherits:
Database show all
Defined in:
lib/dataduck/destination.rb

Direct Known Subclasses

RedshiftDestination

Instance Attribute Summary

Attributes inherited from Database

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Database

#connection, #initialize, #query, #table_names

Constructor Details

This class inherits a constructor from DataDuck::Database

Class Method Details

.destination(name, allow_nil = false) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dataduck/destination.rb', line 37

def self.destination(name, allow_nil = false)
  name = name.to_s

  if DataDuck.destinations[name]
    return DataDuck.destinations[name]
  elsif allow_nil
    return nil
  else
    raise Exception.new("Could not find destination #{ name } in destination configs.")
  end
end

.destination_config(name) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/dataduck/destination.rb', line 21

def self.destination_config(name)
  if DataDuck.config['destinations'].nil? || DataDuck.config['destinations'][name.to_s].nil?
    raise Exception.new("Could not find destination #{ name } in destinations configs.")
  end

  DataDuck.config['destinations'][name.to_s]
end

.load_config!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dataduck/destination.rb', line 5

def self.load_config!
  all_config = DataDuck.config['destinations']
  return if all_config.nil?

  all_config.each_key do |destination_name|
    configuration = all_config[destination_name]
    destination_type = configuration['type']

    if destination_type == "redshift"
      DataDuck.destinations[destination_name] = DataDuck::RedshiftDestination.new(destination_name, configuration)
    else
      raise ArgumentError.new("Unknown type '#{ destination_type }' for destination #{ destination_name }.")
    end
  end
end

.only_destinationObject



49
50
51
52
53
54
55
56
# File 'lib/dataduck/destination.rb', line 49

def self.only_destination
  if DataDuck.destinations.keys.length != 1
    raise ArgumentError.new("Must be exactly 1 destination.")
  end

  destination_name = DataDuck.destinations.keys[0]
  return DataDuck::Destination.destination(destination_name)
end

Instance Method Details

#load_table!(table) ⇒ Object

Raises:

  • (Exception)


29
30
31
# File 'lib/dataduck/destination.rb', line 29

def load_table!(table)
  raise Exception.new("Must implement load_table! in subclass")
end

#recreate_table!(table) ⇒ Object

Raises:

  • (Exception)


33
34
35
# File 'lib/dataduck/destination.rb', line 33

def recreate_table!(table)
  raise Exception.new("Must implement load_table! in subclass")
end