Class: FlareUp::Boot

Inherits:
Object
  • Object
show all
Defined in:
lib/flare_up/boot.rb

Class Method Summary collapse

Class Method Details

.boot(options) ⇒ Object

TODO: This control flow is untested



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/flare_up/boot.rb', line 6

def self.boot(options)
  conn = create_connection(options)
  copy = create_copy_command(options)

  begin
    handle_load_errors(copy.execute(conn))
  rescue CopyCommandError => e
    CLI.output_error("\x1b[31m#{e.message}")
    CLI.bailout(1)
  end

end

.create_connection(options) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/flare_up/boot.rb', line 19

def self.create_connection(options)
  FlareUp::Connection.new(
    options[:redshift_endpoint],
    options[:database],
    options[:redshift_username],
    options[:redshift_password]
  )
end

.create_copy_command(options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/flare_up/boot.rb', line 28

def self.create_copy_command(options)
  copy = FlareUp::CopyCommand.new(
    options[:table],
    options[:data_source],
    options[:aws_access_key],
    options[:aws_secret_key]
  )
  copy.columns = options[:column_list] if options[:column_list]
  copy.options = options[:copy_options] if options[:copy_options]
  copy
end

.handle_load_errors(stl_load_errors) ⇒ Object

TODO: How can we test this?



41
42
43
44
45
46
47
# File 'lib/flare_up/boot.rb', line 41

def self.handle_load_errors(stl_load_errors)
  return if stl_load_errors.empty?
  puts "\x1b[31mThere was an error processing the COPY command.  Displaying the last (#{stl_load_errors.length}) errors."
  stl_load_errors.each do |e|
    puts e.pretty_print
  end
end