Skip to content

Instantly share code, notes, and snippets.

@alex700
Created October 12, 2023 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex700/0cb9e3342e494e0d24c5dab5f5e6e48d to your computer and use it in GitHub Desktop.
Save alex700/0cb9e3342e494e0d24c5dab5f5e6e48d to your computer and use it in GitHub Desktop.
Checksum of Ruby Application
#!/usr/bin/env ruby
require 'digest'
require 'fileutils'
# Function to calculate the checksum for a directory
def calculate_checksum(directory_path, excluded_directories = [])
checksum = Digest::SHA256.new
Dir[File.join(directory_path, '**', '**/*')].each do |file|
# Skip hidden files (those that start with a dot) and excluded directories
next if File.basename(file).start_with?('.') || excluded_directories.any? { |excluded| file.include?(File.join(directory_path, excluded)) }
if File.file?(file)
File.open(file, 'rb') do |f|
while buffer = f.read(4096)
checksum.update(buffer)
end
end
end
end
checksum.hexdigest
end
# Specify the path to your application directory
app_directory = '.'
# Specify the directories to exclude
excluded_directories = ['coverage', 'log', 'node_modules', 'tmp', 'vendor']
# Calculate the checksum for the entire application directory while excluding specific directories
app_checksum = calculate_checksum(app_directory, excluded_directories)
puts "Checksum for the entire application: #{app_checksum}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment