Sha256: 0d6f4da6b5b7ada6affbcf6e2f05ee29586011a049cd2d52e56be70d1eecc2d9

Contents?: true

Size: 1.08 KB

Versions: 24

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module KnapsackPro
  module Config
    class TempFiles
      # relative to the directory where you run knapsack_pro gem (user's project)
      TEMP_DIRECTORY_PATH = '.knapsack_pro'

      def self.ensure_temp_directory_exists!
        unless File.exist?(gitignore_file_path)
          create_temp_directory!
          create_gitignore_file!
        end
      end

      private

      def self.create_temp_directory!
        FileUtils.mkdir_p(TEMP_DIRECTORY_PATH)
      end

      def self.gitignore_file_path
        File.join(TEMP_DIRECTORY_PATH, '.gitignore')
      end

      def self.gitignore_file_content
        <<~GITIGNORE
        # This directory is used by knapsack_pro gem for storing temporary files during tests runtime.
        # Ignore all files, and do not commit this directory into your repository.
        # Learn more at https://knapsackpro.com
        *
        GITIGNORE
      end

      def self.create_gitignore_file!
        File.open(gitignore_file_path, 'w+') do |f|
          f.write(gitignore_file_content)
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
knapsack_pro-7.13.1 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.13.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.12.1 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.12.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.11.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.10.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.9.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.8.2 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.8.1 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.8.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.7.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.6.2 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.6.1 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.6.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.1.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.0.1 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-7.0.0 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-6.0.4 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-6.0.3 lib/knapsack_pro/config/temp_files.rb
knapsack_pro-6.0.2 lib/knapsack_pro/config/temp_files.rb