Class: ChatgptAssistant::Config

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

Overview

This class is responsible for the configuration of the Chatgpt Assistant

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/chatgpt_assistant/config.rb', line 12

def initialize
  @env_type = ENV.fetch("ENV_TYPE", nil)
  @language = ENV.fetch("LANGUAGE", nil)
  @mode = ENV.fetch("MODE", nil)
  @database_host = ENV.fetch("POSTGRES_HOST", nil)
  @database_name = ENV.fetch("POSTGRES_DB", nil)
  @database_username = ENV.fetch("POSTGRES_USER", nil)
  @database_password = ENV.fetch("POSTGRES_PASSWORD", nil)
  @openai_api_key = ENV.fetch("OPENAI_API_KEY", nil)
  @telegram_token = ENV.fetch("TELEGRAM_TOKEN", nil)
  @discord_token = ENV.fetch("DISCORD_TOKEN", nil)
  @discord_client_id = ENV.fetch("DISCORD_CLIENT_ID", nil)
  @ibm_api_key = ENV.fetch("IBM_API_KEY", nil)
  @ibm_url = ENV.fetch("IBM_URL", nil)
  @aws_access_key_id = ENV.fetch("AWS_ACCESS_KEY_ID", nil)
  @aws_secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY", nil)
  @aws_region = ENV.fetch("AWS_REGION", nil)
  @discord_prefix = ENV.fetch("DISCORD_PREFIX", nil)
end

Instance Attribute Details

#aws_access_key_idObject (readonly)

Returns the value of attribute aws_access_key_id.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def aws_access_key_id
  @aws_access_key_id
end

#aws_regionObject (readonly)

Returns the value of attribute aws_region.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def aws_region
  @aws_region
end

#aws_secret_access_keyObject (readonly)

Returns the value of attribute aws_secret_access_key.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def aws_secret_access_key
  @aws_secret_access_key
end

#discord_client_idObject (readonly)

Returns the value of attribute discord_client_id.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def discord_client_id
  @discord_client_id
end

#discord_prefixObject (readonly)

Returns the value of attribute discord_prefix.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def discord_prefix
  @discord_prefix
end

#discord_public_keyObject (readonly)

Returns the value of attribute discord_public_key.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def discord_public_key
  @discord_public_key
end

#discord_tokenObject (readonly)

Returns the value of attribute discord_token.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def discord_token
  @discord_token
end

#env_typeObject (readonly)

Returns the value of attribute env_type.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def env_type
  @env_type
end

#ibm_api_keyObject (readonly)

Returns the value of attribute ibm_api_key.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def ibm_api_key
  @ibm_api_key
end

#ibm_urlObject (readonly)

Returns the value of attribute ibm_url.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def ibm_url
  @ibm_url
end

#languageObject (readonly)

Returns the value of attribute language.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def language
  @language
end

#modeObject (readonly)

Returns the value of attribute mode.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def mode
  @mode
end

#openai_api_keyObject (readonly)

Returns the value of attribute openai_api_key.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def openai_api_key
  @openai_api_key
end

#smtp_addressObject (readonly)

Returns the value of attribute smtp_address.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def smtp_address
  @smtp_address
end

#smtp_authenticationObject (readonly)

Returns the value of attribute smtp_authentication.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def smtp_authentication
  @smtp_authentication
end

#smtp_domainObject (readonly)

Returns the value of attribute smtp_domain.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def smtp_domain
  @smtp_domain
end

#smtp_enable_starttls_autoObject (readonly)

Returns the value of attribute smtp_enable_starttls_auto.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def smtp_enable_starttls_auto
  @smtp_enable_starttls_auto
end

#smtp_passwordObject (readonly)

Returns the value of attribute smtp_password.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def smtp_password
  @smtp_password
end

#smtp_portObject (readonly)

Returns the value of attribute smtp_port.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def smtp_port
  @smtp_port
end

#smtp_user_nameObject (readonly)

Returns the value of attribute smtp_user_name.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def smtp_user_name
  @smtp_user_name
end

#telegram_tokenObject (readonly)

Returns the value of attribute telegram_token.



32
33
34
# File 'lib/chatgpt_assistant/config.rb', line 32

def telegram_token
  @telegram_token
end

Instance Method Details

#create_dbObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chatgpt_assistant/config.rb', line 50

def create_db
  db_connection
  return if database_exists?

  ActiveRecord::Base.establish_connection(
    adapter: "postgresql",
    host: database_host,
    port: 5432,
    database: "postgres",
    username: database_username,
    password: database_password
  )
  ActiveRecord::Base.logger = Logger.new($stdout) if ENV["ENV_TYPE"] == "development"
  ActiveRecord::Base.connection.create_database(database_name)
end

#db_connectionObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chatgpt_assistant/config.rb', line 38

def db_connection
  ActiveRecord::Base.establish_connection(
    adapter: "postgresql",
    host: database_host,
    port: 5432,
    database: database_name,
    username: database_username,
    password: database_password
  )
  ActiveRecord::Base.logger = Logger.new($stdout) if ENV["ENV_TYPE"] == "development"
end

#migrateObject



66
67
68
69
70
71
72
73
74
# File 'lib/chatgpt_assistant/config.rb', line 66

def migrate
  db_connection
  ActiveRecord::Base.logger = Logger.new($stdout) if ENV["ENV_TYPE"] == "development"
  VisitorMigration.new.migrate(:up)
  UserMigration.new.migrate(:up)
  ChatMigration.new.migrate(:up)
  MessageMigration.new.migrate(:up)
  ErrorMigration.new.migrate(:up)
end