Class: Kybus::CLI::Bot::Config::DBGenerator

Inherits:
FileProvider show all
Defined in:
lib/kybus/cli/bot/file_providers/db_generator.rb

Instance Method Summary collapse

Methods inherited from FileProvider

autoregister!, #bot_name, #bot_name_class, #bot_name_constantize, #bot_name_snake_case, #generate, #initialize, #keep_files, #skip_file?

Constructor Details

This class inherits a constructor from Kybus::CLI::Bot::FileProvider

Instance Method Details

#make_contentsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kybus/cli/bot/file_providers/db_generator.rb', line 14

def make_contents
  case @config[:db_adapter]
  when 'sequel'
    <<~RUBY
      # frozen_string_literal: true

      require 'sequel'

      DB = Sequel.connect(APP_CONF['database'])

      def run_migrations!
        require 'kybus/bot/migrator'
        require 'sequel/core'
        Kybus::Bot::Migrator.run_migrations!(APP_CONF['bots']['main']['state_repository'])
        Sequel.extension :migration
        Sequel::Migrator.run(DB, 'models/migrations')
      end
    RUBY
  when 'activerecord'
    <<~RUBY
      # frozen_string_literal: true

      require 'active_record'

      ActiveRecord::Base.establish_connection(APP_CONF['database'])
    RUBY
  when 'dynamoid'
    <<~RUBY
      def run_migrations!
        require 'kybus/bot/migrator'
        Kybus::Bot::Migrator.run_migrations!(APP_CONF['bots']['main']['state_repository'])
      end
    RUBY
  end
end

#saving_pathObject



10
11
12
# File 'lib/kybus/cli/bot/file_providers/db_generator.rb', line 10

def saving_path
  'config_loaders/db.rb'
end