Class: RedshiftETL::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift_etl/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
16
# File 'lib/redshift_etl/config.rb', line 10

def initialize(file_path)
  fail "plz provide a file" if file_path.blank?
  @config = YAML.load(File.open(file_path))
rescue
  puts $!
  fail "Did you provide a valid YAML file?"
end

Instance Method Details

#check!Object



94
95
96
97
98
# File 'lib/redshift_etl/config.rb', line 94

def check!
  fail "plz set AWS_SECRET_ACCESS_KEY" if s3_secret_access_key.blank?
  fail "plz set REDSHIFT_DATABASE_URL" if redshift_connection.blank?
  fail "plz set AWS_ACCESS_KEY_ID"     if s3_access_key_id.blank?
end

#columnsObject



70
71
72
# File 'lib/redshift_etl/config.rb', line 70

def columns
  @config["columns"]
end

#connection_stringObject



54
55
56
# File 'lib/redshift_etl/config.rb', line 54

def connection_string
  @config["connection_string"]
end

#disabled?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/redshift_etl/config.rb', line 30

def disabled?
  !enabled?
end

#enabled?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/redshift_etl/config.rb', line 26

def enabled?
  @config["enabled"]
end

#filenameObject



58
59
60
# File 'lib/redshift_etl/config.rb', line 58

def filename
  @config["filename"] + '.csv'
end

#final_s3_pathObject



22
23
24
# File 'lib/redshift_etl/config.rb', line 22

def final_s3_path
  "files/#{redshift_schema}/#{redshift_table}/"
end

#incremental_updates?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/redshift_etl/config.rb', line 38

def incremental_updates?
  @config["incremental_updates"]
end

#primary_keyObject



34
35
36
# File 'lib/redshift_etl/config.rb', line 34

def primary_key
  @config["primary_key"]
end

#queryObject



46
47
48
# File 'lib/redshift_etl/config.rb', line 46

def query
  @config["query"]
end

#redshift_connectionObject



74
75
76
# File 'lib/redshift_etl/config.rb', line 74

def redshift_connection
  ENV['REDSHIFT_DATABASE_URL']
end

#redshift_schemaObject



66
67
68
# File 'lib/redshift_etl/config.rb', line 66

def redshift_schema
  @config["redshift_schema"]
end

#redshift_tableObject



62
63
64
# File 'lib/redshift_etl/config.rb', line 62

def redshift_table
  @config["redshift_table"]
end

#s3Object



100
101
102
# File 'lib/redshift_etl/config.rb', line 100

def s3
  AWS::S3.new(access_key_id: s3_access_key_id, secret_access_key: s3_secret_access_key)
end

#s3_access_key_idObject



78
79
80
# File 'lib/redshift_etl/config.rb', line 78

def s3_access_key_id
  ENV['AWS_ACCESS_KEY_ID']
end

#s3_bucketObject



104
105
106
# File 'lib/redshift_etl/config.rb', line 104

def s3_bucket
  s3.buckets[s3_bucket_name]
end

#s3_bucket_nameObject



90
91
92
# File 'lib/redshift_etl/config.rb', line 90

def s3_bucket_name
  "tanga-redshift"
end

#s3_regionObject



86
87
88
# File 'lib/redshift_etl/config.rb', line 86

def s3_region
  "us-east-1"
end

#s3_secret_access_keyObject



82
83
84
# File 'lib/redshift_etl/config.rb', line 82

def s3_secret_access_key
  ENV['AWS_SECRET_ACCESS_KEY']
end

#table_nameObject



50
51
52
# File 'lib/redshift_etl/config.rb', line 50

def table_name
  @config["table_name"]
end

#temp_s3_pathObject



18
19
20
# File 'lib/redshift_etl/config.rb', line 18

def temp_s3_path
  "tmp/#{redshift_schema}/#{redshift_table}/#{temp_key}/"
end

#update_timestamp_columnObject



42
43
44
# File 'lib/redshift_etl/config.rb', line 42

def update_timestamp_column
  @config["update_timestamp_column"]
end