Class: Sourced::Rails::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/sourced/rails/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_bin_fileObject



37
38
39
40
# File 'lib/sourced/rails/install_generator.rb', line 37

def copy_bin_file
  copy_file 'bin_sourced', 'bin/sourced'
  chmod 'bin/sourced', 0o755
end

#copy_initializer_fileObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sourced/rails/install_generator.rb', line 15

def copy_initializer_file
  create_file 'config/initializers/sourced.rb' do
    <<~CONTENT
      # frozen_string_literal: true

      require 'sourced'
      require 'sourced/backends/active_record_backend'

      # This table prefix is used to generate the initial database migrations.
      # If you change the table prefix here,
      # make sure to migrate your database to the new table names.
      Sourced::Backends::ActiveRecordBackend.table_prefix = '#{table_prefix}'

      # Configure Sors to use the ActiveRecord backend
      Sourced.configure do |config|
        config.backend = Sourced::Backends::ActiveRecordBackend.new
        config.logger = Rails.logger
      end
    CONTENT
  end
end

#create_migration_fileObject



42
43
44
# File 'lib/sourced/rails/install_generator.rb', line 42

def create_migration_file
  migration_template 'create_sourced_tables.rb.erb', File.join(db_migrate_path, 'create_sourced_tables.rb')
end