class DockerDirEnv::Generators::InstallGenerator

Public Instance Methods

install() click to toggle source

Installs the required files in the application

# File lib/generators/docker_dir_env/install_generator.rb, line 15
def install
  copy_envrc
  copy_database_yml
  copy_docker_db_setup_sh
  system(`direnv allow`)
  print("#{readme}\n")
end

Private Instance Methods

copy_database_yml() click to toggle source
# File lib/generators/docker_dir_env/install_generator.rb, line 30
def copy_database_yml
  template('config/database.yml', 'config/database.yml')
end
copy_docker_db_setup_sh() click to toggle source
# File lib/generators/docker_dir_env/install_generator.rb, line 34
def copy_docker_db_setup_sh
  FileUtils.mkdir_p('lib/scripts')
  copy_file('lib/scripts/docker-db-setup.sh', 'lib/scripts/docker-db-setup.sh')
  system(`chmod +x lib/scripts/docker-db-setup.sh`)
end
copy_envrc() click to toggle source
# File lib/generators/docker_dir_env/install_generator.rb, line 25
def copy_envrc
  @app_name = Rails.application.class.name&.deconstantize&.underscore
  template('.envrc', '.envrc')
end
readme() click to toggle source
# File lib/generators/docker_dir_env/install_generator.rb, line 40
      def readme
        <<~README
          Thanks for using docker_dir_env!
          Make sure to provide the databases credentials by configuring them with
          `EDITOR=vim rails credentials:edit` OR
          `EDITOR=vim rails credentials:edit -e development` (and the other envs)

           Your can use your favourite editor instead of vim.

          Provide the following structure inside the credentials:
          database:
            username: #{Rails.application.class.name&.deconstantize&.underscore}_RAILS_ENV
            password: YOUR_PASSWORD
        README
      end